/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:27
*/
KISSY.add("editor/iframe-content-tpl",[],'<!doctype html>\n<html>\n<head>{doctype}\n    <title>{title}</title>\n    {style}\n    {links}\n    </head> \n<body class="ks-editor">\n{data}\n{script}\n</body> \n</html>');
KISSY.add("editor/render-xtpl",[],function(){return function(a){var b,o=this;b=this.config.utils;var t=b.runBlockCommand,m=b.renderOutput,x=b.getProperty,p=b.getPropertyOrRunCommand;b='<div class="';var e=p(o,a,{},"prefixCls",0,1);b+=m(e,!0);b+='editor-tools"\n     id="ks-editor-tools-';e=p(o,a,{},"id",0,2);b+=m(e,!0);b+='">\n\n</div>\n\n<\!--\nhttp://johanbrook.com/browsers/native-momentum-scrolling-ios-5/\nios \u4e0d\u80fd\u653e\u5728 iframe \u4e0a\uff01\n--\>\n\n<div class="';e=p(o,a,{},"prefixCls",0,11);b+=m(e,!0);b+='editor-textarea-wrap"\n\n';
var e={},i=[],v=x(o,a,"mobile",0,13);i.push(v);e.params=i;e.fn=function(){return'\nstyle="overflow:scroll;-webkit-overflow-scrolling:touch;"\n'};b+=t(o,a,e,"if",13);b+='\n\nid="ks-editor-textarea-wrap-';e=p(o,a,{},"id",0,17);b+=m(e,!0);b+='"\n>\n\n<textarea\n        id="ks-editor-textarea-';e=p(o,a,{},"id",0,21);b+=m(e,!0);b+='"\n        class="';e=p(o,a,{},"prefixCls",0,22);b+=m(e,!0);b+='editor-textarea"\n\n';e={};i=[];v=x(o,a,"textareaAttrs",0,24);i.push(v);e.params=i;e.fn=function(a){var e;e=
"\n";var i=p(o,a,{},"xindex",0,25);e+=m(i,!0);e+='="';a=p(o,a,{},".",0,25);e+=m(a,!0);return e+'"\n'};b+=t(o,a,e,"each",24);b+="\n\n";e={};i=[];x=x(o,a,"mode",0,28);i.push(x);e.params=i;e.fn=function(){return'\nstyle="display:none"\n'};b+=t(o,a,e,"if",28);b+="\n\n>";t=p(o,a,{},"data",0,32);b+=m(t,!0);b+='</textarea>\n\n</div>\n\n<div class="';t=p(o,a,{},"prefixCls",0,36);b+=m(t,!0);b+='editor-status"\n     id="ks-editor-status-';a=p(o,a,{},"id",0,37);b+=m(a,!0);return b+'">\n\n</div>'}});
KISSY.add("editor/render",["component/control","./render-xtpl"],function(a,b){var o=b("component/control"),t=b("./render-xtpl");return o.getDefaultRender().extend({beforeCreateDom:function(b,o){a.mix(b,{mobile:a.UA.mobile});a.mix(o,{textarea:"#ks-editor-textarea-{id}",toolBarEl:"#ks-editor-tools-{id}",statusBarEl:"#ks-editor-status-{id}"})}},{ATTRS:{contentTpl:{value:t}}})});
KISSY.add("editor/base",["html-parser","component/control","./render"],function(a,b){var o=b("html-parser"),t=b("component/control"),m=b("./render");return t.extend({},{Config:{},XHTML_DTD:o.DTD,ATTRS:{textarea:{},textareaAttrs:{view:1},iframe:{},window:{},document:{},toolBarEl:{},statusBarEl:{},handleMouseEvents:{value:!1},focusable:{value:!1},mode:{view:1,value:1},data:{view:1},customStyle:{value:""},customLink:{value:[]},xrender:{value:m}},xclass:"editor"})});
KISSY.add("editor/utils",["node","./base"],function(a,b){var o=b("node"),t=b("./base"),m=a.DOM,x=a.UA,p={debugUrl:function(e){var i=a.Config;i.debug||(e=e.replace(/\.(js|css)/i,"-min.$1"));-1===e.indexOf("?t")&&(e=-1!==e.indexOf("?")?e+"&":e+"?",e+="t="+encodeURIComponent(i.tag));return a.config("base")+"editor/"+e},lazyRun:function(a,i,b){var s=a[i],k=a[b];a[i]=function(){s.apply(this,arguments);a[i]=a[b];return k.apply(this,arguments)}},getXY:function(a,i){var b=a.left,s=a.top,k=i.get("window")[0],
b=b-m.scrollLeft(k),s=s-m.scrollTop(k),k=i.get("iframe").offset(),b=b+k.left,s=s+k.top;return{left:b,top:s}},tryThese:function(){for(var a,i=0,b=arguments.length;i<b;i++){var s=arguments[i];try{a=s();break}catch(k){}}return a},clearAllMarkers:function(a){for(var i in a)a[i]._4eClearMarkers(a,!0,void 0)},ltrim:function(a){return a.replace(/^\s+/,"")},rtrim:function(a){return a.replace(/\s+$/,"")},isNumber:function(e){return/^\d+(.\d+)?$/.test(a.trim(e))},verifyInputs:function(e){for(var i=0;i<e.length;i++){var b=
new o(e[i]),s=a.trim(p.valInput(b)),k=b.attr("data-verify"),b=b.attr("data-warning");if(k&&!RegExp(k).test(s))return alert(b),!1}return!0},sourceDisable:function(a,b){a.on("sourceMode",b.disable,b);a.on("wysiwygMode",b.enable,b)},resetInput:function(a){var b=a.attr("placeholder");b&&x.ie?(a.addClass("ks-editor-input-tip"),a.val(b)):x.ie||a.val("")},valInput:function(a,b){if(void 0===b)return a.hasClass("ks-editor-input-tip")?"":a.val();a.removeClass("ks-editor-input-tip");a.val(b)},placeholder:function(e,
b){e.attr("placeholder",b);x.ie&&(e.on("blur",function(){a.trim(e.val())||(e.addClass("ks-editor-input-tip"),e.val(b))}),e.on("focus",function(){e.removeClass("ks-editor-input-tip");a.trim(e.val())===b&&e.val("")}))},normParams:function(e){var e=a.clone(e),b;for(b in e){var v=e[b];"function"===typeof v&&(e[b]=v())}return e},preventFocus:function(a){x.ie?a.unselectable():a.attr("onmousedown","return false;")},injectDom:function(e){a.mix(m,e);for(var b in e)(function(b){o.prototype[b]=function(){var i=
[].slice.call(arguments,0);i.unshift(this[0]);return(i=e[b].apply(null,i))&&(i.nodeType||a.isWindow(i))?new o(i):a.isArray(i)&&(i.__IS_NODELIST||i[0]&&i[0].nodeType)?new o(i):i}})(b)},addRes:function(){var b=this.__res=this.__res||[];b.push.apply(b,a.makeArray(arguments))},destroyRes:function(){for(var a=this.__res||[],b=0;b<a.length;b++){var v=a[b];"function"===typeof v?v():v.destroy?v.destroy():v.remove&&v.remove()}this.__res=[]},getQueryCmd:function(a){return"query"+("-"+a).replace(/-(\w)/g,function(a,
b){return b.toUpperCase()})+"Value"}};return t.Utils=p});
KISSY.add("editor/focusManager",["./base"],function(a,b){function o(){var a=this;a.__iframeFocus=v;e=a;p&&clearTimeout(p);p=setTimeout(function(){a.fire("focus")},30)}function t(){var a=this;a.__iframeFocus=s;e=k;p&&clearTimeout(p);p=setTimeout(function(){a.fire("blur")},30)}var m=b("./base"),x={},p,e,i={currentInstance:function(){return e},getInstance:function(a){return x[a]},register:function(a){x[a.get("id")]=a},add:function(a){this.register(a);a.get("window").on("focus",o,a).on("blur",t,a)},remove:function(a){delete x[a.get("id")];
a.get("window").detach("focus",o,a).detach("blur",t,a)}},v=!0,s=!1,k=null;m.focusManager=i;m.getInstances=function(){return x};return i});
KISSY.add("editor/dom",["node","./base","./utils"],function(a,b){function o(a,d){var c=a[d?"next":"prev"](void 0,1);if(c&&c[0].nodeType===i.ELEMENT_NODE){for(var j=[];c.attr("_ke_bookmark")||c._4eIsEmptyInlineRemovable(void 0);)if(j.push(c),c=d?c.next(void 0,1):c.prev(void 0,1),!c)return;if(a._4eIsIdentical(c,void 0)){for(var h=new t(d?a[0].lastChild:a[0].firstChild);j.length;)j.shift()._4eMove(a,!d,void 0);c._4eMoveChildren(a,!d,void 0);c.remove();h[0]&&h[0].nodeType===i.ELEMENT_NODE&&h._4eMergeSiblings()}}}
var t=b("node"),m=b("./base"),x=b("./utils"),p=m.XHTML_DTD,e=a.DOM,i=e.NodeType,v=a.UA,s={a:1,abbr:1,acronym:1,address:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,s:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,"var":1};m.PositionType={POSITION_IDENTICAL:0,POSITION_DISCONNECTED:1,POSITION_FOLLOWING:2,POSITION_PRECEDING:4,POSITION_IS_CONTAINED:8,POSITION_CONTAINS:16};var k=m.PositionType,u={block:1,"list-item":1,table:1,"table-row-group":1,"table-header-group":1,
"table-footer-group":1,"table-row":1,"table-column-group":1,"table-column":1,"table-cell":1,"table-caption":1},w={hr:1},n=function(a){return a&&(a[0]||a)};x.injectDom({_4eSameLevel:function(a,d){var d=n(d),c=a.parentNode;return c&&c===d.parentNode},_4eIsBlockBoundary:function(l,d){var c=a.merge(w,d);return!(!u[e.css(l,"display")]&&!c[e.nodeName(l)])},_4eIndex:function(a,d){for(var c=a.parentNode.childNodes,j,h=-1,f=0;f<c.length;f++)if(j=c[f],!d||!(3===j.nodeType&&j.previousSibling&&3===j.previousSibling.nodeType))if(h++,
j===a)return h;return-1},_4eMove:function(a,d,c){d=n(d);c?d.insertBefore(a,d.firstChild):d.appendChild(a)},_4eIsIdentical:function(a,d){if(!d)return!1;d=n(d);if(e.nodeName(a)!==e.nodeName(d))return!1;var c=a.attributes,j,h,f=d.attributes,g=c.length,y=f.length;if(g!==y)return!1;for(var b=0;b<g;b++)if(j=c[b],h=j.name,j.specified&&e.attr(a,h)!==e.attr(d,h))return!1;if(8>v.ieMode)for(b=0;b<y;b++)if(j=f[b],h=j.name,j.specified&&e.attr(a,h)!==e.attr(d,h))return!1;return!0},_4eIsEmptyInlineRemovable:function(l){if(!p.$removeEmpty[e.nodeName(l)])return!1;
for(var l=l.childNodes,d=0,c=l.length;d<c;d++){var b=l[d],h=b.nodeType;if(!(h===i.ELEMENT_NODE&&b.getAttribute("_ke_bookmark"))&&(h===i.ELEMENT_NODE&&!e._4eIsEmptyInlineRemovable(b)||h===e.NodeType.TEXT_NODE&&a.trim(b.nodeValue)))return!1}return!0},_4eMoveChildren:function(a,d,c){d=n(d);if(a!==d)if(c)for(;c=a.lastChild;)d.insertBefore(a.removeChild(c),d.firstChild);else for(;c=a.firstChild;)d.appendChild(a.removeChild(c))},_4eMergeSiblings:function(a){a=new t(a);s[a.nodeName()]&&(o(a,!0),o(a))},_4eSplitText:function(a,
d){var c=a.ownerDocument;if(a.nodeType===e.NodeType.TEXT_NODE){if(v.ie&&d===a.nodeValue.length){var b=c.createTextNode("");e.insertAfter(b,a);return b}b=a.splitText(d);c.documentMode&&(c=c.createTextNode(""),e.insertAfter(c,b),e.remove(c));return b}},_4eParents:function(a,d){var c=[];c.__IS_NODELIST=1;do c[d?"push":"unshift"](a);while(a=a.parentNode);return c},_4eNextSourceNode:function(a,d,c,b){if(b&&!b.call)var h=n(b),b=function(f){return f!==h};var d=!d&&a.firstChild,f=a;if(!d){if(a.nodeType===
i.ELEMENT_NODE&&b&&!1===b(a,!0))return null;d=a.nextSibling}for(;!d&&(f=f.parentNode);){if(b&&!1===b(f,!0))return null;d=f.nextSibling}return!d||b&&!1===b(d)?null:c&&c!==d.nodeType?e._4eNextSourceNode(d,!1,c,b):d},_4ePreviousSourceNode:function(a,d,c,b){if(b&&!b.call)var h=n(b),b=function(a){return a!==h};var d=!d&&a.lastChild,f=a;if(!d){if(a.nodeType===i.ELEMENT_NODE&&b&&!1===b(a,!0))return null;d=a.previousSibling}for(;!d&&(f=f.parentNode);){if(b&&!1===b(f,!0))return null;d=f.previousSibling}return!d||
b&&!1===b(d)?null:c&&d.nodeType!==c?e._4ePreviousSourceNode(d,!1,c,b):d},_4eCommonAncestor:function(a,d){d=n(d);if(a===d)return a;if(e.contains(d,a))return d;var c=a;do if(e.contains(c,d))return c;while(c=c.parentNode);return null},_4eHasAttributes:9>v.ieMode?function(a){for(var d=a.attributes,c=0;c<d.length;c++){var b=d[c];switch(b.name){case "class":if(a.getAttribute("class"))return!0;break;default:if(b.specified)return!0}}return!1}:function(a){v.gecko&&a.removeAttribute("_moz_dirty");return a.hasAttributes()},
_4ePosition:function(a,d){var b=n(d);if(a.compareDocumentPosition)return a.compareDocumentPosition(b);if(a===b)return k.POSITION_IDENTICAL;if(a.nodeType===i.ELEMENT_NODE&&b.nodeType===i.ELEMENT_NODE){if(e.contains(a,b))return k.POSITION_CONTAINS+k.POSITION_PRECEDING;if(e.contains(b,a))return k.POSITION_IS_CONTAINED+k.POSITION_FOLLOWING;if("sourceIndex"in a)return 0>a.sourceIndex||0>b.sourceIndex?k.POSITION_DISCONNECTED:a.sourceIndex<b.sourceIndex?k.POSITION_PRECEDING:k.POSITION_FOLLOWING}for(var j=
e._4eAddress(a),b=e._4eAddress(b),h=Math.min(j.length,b.length),f=0;f<=h-1;f++)if(j[f]!==b[f])return j[f]<b[f]?k.POSITION_PRECEDING:k.POSITION_FOLLOWING;return j.length<b.length?k.POSITION_CONTAINS+k.POSITION_PRECEDING:k.POSITION_IS_CONTAINED+k.POSITION_FOLLOWING},_4eAddress:function(a,b){for(var c=[],j=a.ownerDocument.documentElement,h=a;h&&h!==j;)c.unshift(e._4eIndex(h,b)),h=h.parentNode;return c},_4eRemove:function(a,b){var c=a.parentNode;if(c){if(b)for(var e;e=a.firstChild;)c.insertBefore(a.removeChild(e),
a);c.removeChild(a)}return a},_4eTrim:function(a){e._4eLtrim(a);e._4eRtrim(a)},_4eLtrim:function(a){for(var b;b=a.firstChild;){if(b.nodeType===e.NodeType.TEXT_NODE){var c=x.ltrim(b.nodeValue),j=b.nodeValue.length;if(c)c.length<j&&(e._4eSplitText(b,j-c.length),a.removeChild(a.firstChild));else{a.removeChild(b);continue}}break}},_4eRtrim:function(a){for(var b;b=a.lastChild;){if(b.type===e.NodeType.TEXT_NODE){var c=x.rtrim(b.nodeValue),j=b.nodeValue.length;if(c)c.length<j&&(e._4eSplitText(b,c.length),
a.removeChild(a.lastChild));else{a.removeChild(b);continue}}break}!v.ie&&!v.opera&&(b=a.lastChild)&&1===b.nodeType&&"br"===e.nodeName(b)&&a.removeChild(b)},_4eAppendBogus:function(b){for(var d=b.lastChild;d&&d.nodeType===e.NodeType.TEXT_NODE&&!a.trim(d.nodeValue);)d=d.previousSibling;if(!d||d.nodeType===e.NodeType.TEXT_NODE||"br"!==e.nodeName(d))d=v.opera?b.ownerDocument.createTextNode(""):b.ownerDocument.createElement("br"),b.appendChild(d)},_4eSetMarker:function(b,d,c,e){var b=new t(b),h=b.data("list_marker_id")||
b.data("list_marker_id",a.guid()).data("list_marker_id"),f=b.data("list_marker_names")||b.data("list_marker_names",{}).data("list_marker_names");d[h]=b;f[c]=1;return b.data(c,e)},_4eClearMarkers:function(a,b,c){var a=new t(a),e=a.data("list_marker_names"),h=a.data("list_marker_id"),f;for(f in e)a.removeData(f);a.removeData("list_marker_names");c&&(a.removeData("list_marker_id"),delete b[h])},_4eCopyAttributes:function(a,b,c){for(var b=new t(b),j=a.attributes,c=c||{},h=0;h<j.length;h++){var f=j[h],
g=f.name.toLowerCase(),y;if(!(g in c))if("checked"===g&&(y=e.attr(a,g)))b.attr(g,y);else if(f.specified||v.ie&&f.value&&"value"===g)y=e.attr(a,g),null===y&&(y=f.nodeValue),b.attr(g,y)}""!==a.style.cssText&&(b[0].style.cssText=a.style.cssText)},_4eIsEditable:function(a){a=e.nodeName(a);return(a=!p.$nonEditable[a]&&(p[a]||p.span))&&a["#text"]},_4eGetByAddress:function(a,b,c){for(var a=a.documentElement,e=0;a&&e<b.length;e++){var h=b[e];if(c)for(var f=-1,g=0;g<a.childNodes.length;g++){var y=a.childNodes[g];
if(!(!0===c&&3===y.nodeType&&y.previousSibling&&3===y.previousSibling.nodeType)&&(f++,f===h)){a=y;break}}else a=a.childNodes[h]}return a}})});
KISSY.add("editor/walker",["./base","node"],function(a,b){function o(a,b){if(this._.end)return i;var h,f=this.range,g,d=this.guard,z=this.type,q=a?"_4ePreviousSourceNode":"_4eNextSourceNode";if(!this._.start&&(this._.start=1,f.trim(),f.collapsed))return this.end(),i;if(!a&&!this._.guardLTR){var l=f.endContainer[0],n=l.childNodes[f.endOffset];this._.guardLTR=function(a,r){return r&&(l===a||"body"===s.nodeName(a))?!1:a!==n}}if(a&&!this._.guardRTL){var k=f.startContainer[0],v=0<f.startOffset&&k.childNodes[f.startOffset-
1]||null;this._.guardRTL=function(a,r){return r&&(k===a||"body"===s.nodeName(a))?!1:a!==v}}var J=a?this._.guardRTL:this._.guardLTR;g=d?function(a,r){return J(a,r)===e?e:d(a,r)}:J;this.current?h=this.current[q](e,z,g):a?(h=f.endContainer,0<f.endOffset?(h=new u(h[0].childNodes[f.endOffset-1]),g(h[0])===e&&(h=i)):h=g(h,p)===e?i:h._4ePreviousSourceNode(p,z,g,void 0)):(h=f.startContainer,h=new u(h[0].childNodes[f.startOffset]),h.length?g(h[0])===e&&(h=i):h=g(f.startContainer,p)===e?i:f.startContainer._4eNextSourceNode(p,
z,g,void 0));for(;h&&!this._.end;){this.current=h;if(!this.evaluator||this.evaluator(h[0])!==e){if(!b)return h}else if(b&&this.evaluator)return e;h=h[q](e,z,g)}this.end();return this.current=i}function t(a){for(var b,h=i;b=o.call(this,a);)h=b;return h}function m(a){this.range=a;this.guard=this.evaluator=i;this._={}}var x=b("./base"),p=!0,e=!1,i=null,v=a.UA,s=a.DOM,k=x.XHTML_DTD,u=b("node");a.augment(m,{end:function(){this._.end=1},next:function(){return o.call(this)},previous:function(){return o.call(this,
p)},checkForward:function(){return o.call(this,e,p)!==e},checkBackward:function(){return o.call(this,p,p)!==e},lastForward:function(){return t.call(this)},lastBackward:function(){return t.call(this,p)},reset:function(){delete this.current;this._={}},_iterator:o});a.mix(m,{blockBoundary:function(a){return function(b){return!(b.nodeType===s.NodeType.ELEMENT_NODE&&s._4eIsBlockBoundary(b,a))}},bookmark:function(a,b){function h(a){return"span"===s.nodeName(a)&&s.attr(a,"_ke_bookmark")}return function(f){var g,
d;g=f.nodeType===s.NodeType.TEXT_NODE&&(d=f.parentNode)&&h(d);g=a?g:g||h(f);return!!(b^g)}},whitespaces:function(b){return function(d){d=d.nodeType===s.NodeType.TEXT_NODE&&!a.trim(d.nodeValue);return!!(b^d)}},invisible:function(a){var b=m.whitespaces();return function(h){h=b(h)||h.nodeType===s.NodeType.ELEMENT_NODE&&!h.offsetHeight;return!!(a^h)}}});var w=/^[\t\r\n ]*(?:&nbsp;|\xa0)$/,n=m.whitespaces(),l=m.bookmark(),d=function(a){var b=s.nodeName(a);return l(a)||n(a)||1===a.nodeType&&b in k.$inline&&
!(b in k.$empty)};x.Utils.injectDom({_4eGetBogus:function(a){a=new u(a);do a=a._4ePreviousSourceNode();while(a&&d(a[0]));return a&&(!v.ie?"br"===a.nodeName():3===a[0].nodeType&&w.test(a.text()))?a[0]:!1}});return x.Walker=m});
KISSY.add("editor/elementPath",["node","./base","./dom"],function(a,b){function o(a){for(var b=p,k=p,u=[];a;){if(a[0].nodeType===m.NodeType.ELEMENT_NODE){this.lastElement||(this.lastElement=a);var o=a.nodeName();if(!k&&(!b&&e[o]&&(b=a),i[o])){var n;if(n=!b)if(n="div"===o){a:{n=a[0].childNodes;for(var l=0,d=n.length;l<d;l++){var c=n[l];if(c.nodeType===m.NodeType.ELEMENT_NODE&&x.$block[c.nodeName.toLowerCase()]){n=!0;break a}}n=!1}n=!n}n?b=a:k=a}u.push(a);if("body"===o)break}a=a.parent()}this.block=
b;this.blockLimit=k;this.elements=u}b("node");var t=b("./base");b("./dom");var m=a.DOM,x=t.XHTML_DTD,p=null,e={address:1,blockquote:1,dl:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1,li:1,dt:1,dd:1},i={body:1,div:1,table:1,tbody:1,tr:1,td:1,th:1,caption:1,form:1};o.prototype={constructor:o,compare:function(a){var b=this.elements,a=a&&a.elements;if(!a||b.length!==a.length)return!1;for(var e=0;e<b.length;e++)if(!m.equals(b[e],a[e]))return!1;return!0},contains:function(a){for(var b=this.elements,e=0;e<b.length;e++)if(b[e].nodeName()in
a)return b[e];return p},toString:function(){var a=this.elements,b,e=[];for(b=0;b<a.length;b++)e.push(a[b].nodeName());return e.toString()}};return t.ElementPath=o});
KISSY.add("editor/range","./dom,node,./utils,./walker,./base,./elementPath".split(","),function(a,b){function o(b){var g=b.nodeType!==j.NodeType.TEXT_NODE&&j.nodeName(b)in f.$removeEmpty,r=b.nodeType===j.NodeType.TEXT_NODE&&!a.trim(b.nodeValue),b=!!b.parentNode.getAttribute("_ke_bookmark");return g||r||b}function t(a){return!q(a)&&!D(a)}function m(b){var f=n;return function(r){if(D(r))return w;if(r.nodeType===j.NodeType.TEXT_NODE){if(a.trim(r.nodeValue).length)return n}else if(r.nodeType===j.NodeType.ELEMENT_NODE){r=
j.nodeName(r);if(!G[r])if(!b&&!h.ie&&r==="br"&&!f)f=w;else return n}return w}}function x(a,b){var r=a.startContainer,f=a.endContainer,g=a.startOffset,h=a.endOffset,d,e=n,c=n,z,q=a.document,Q;b>0&&(z=q.createDocumentFragment());if(a.collapsed)return z;a.optimizeBookmark();if(f[0].nodeType===j.NodeType.TEXT_NODE){c=w;f=f._4eSplitText(h)}else if(f[0].childNodes.length>0)if(h>=f[0].childNodes.length){f=new i(f[0].appendChild(q.createTextNode("")));Q=w}else f=new i(f[0].childNodes[h]);if(r[0].nodeType===
j.NodeType.TEXT_NODE){e=w;r._4eSplitText(g)}else if(g)if(g>=r[0].childNodes.length){r=new i(r[0].appendChild(q.createTextNode("")));d=w}else r=new i(r[0].childNodes[g].previousSibling);else{d=new i(q.createTextNode(""));r.prepend(d);r=d;d=w}var l=r._4eParents(),K=f._4eParents();l.each(function(a,b){l[b]=a});K.each(function(a,b){K[b]=a});for(var H,D,q=0;q<l.length;q++){H=l[q];D=K[q];if(!H.equals(D))break}for(var g=z,C,k,B=q;B<l.length;B++){C=l[B];h=b>0&&!C.equals(r)?g.appendChild(C.clone()[0]):null;
C=C[0].nextSibling;k=K[B];for(var o=f[0],m=k&&k[0];C;){if(m===C||o===C)break;k=C.nextSibling;if(b===2)g.appendChild(C.cloneNode(w));else{if(y[C.nodeName.toLowerCase()]){var p=C.cloneNode(w);C.innerHTML="";C=p}else j._4eRemove(C);b===1&&g.appendChild(C)}C=k}h&&(g=h)}for(g=z;q<K.length;q++){C=K[q];h=b>0&&!C.equals(f)?g.appendChild(C.clone()[0]):null;if(!l[q]||!C._4eSameLevel(l[q]))for(C=C[0].previousSibling;C;){k=C.previousSibling;if(b===2)g.insertBefore(C.cloneNode(w),g.firstChild);else{j._4eRemove(C);
b===1&&g.insertBefore(C,g.firstChild)}C=k}h&&(g=h)}if(b===2){if(e){H=r[0];if(H.nodeType===j.NodeType.TEXT_NODE&&H.nextSibling&&H.nextSibling.nodeType===j.NodeType.TEXT_NODE){H.data=H.data+H.nextSibling.data;H.parentNode.removeChild(H.nextSibling)}}if(c){c=f[0];if(c.nodeType===j.NodeType.TEXT_NODE&&c.previousSibling&&c.previousSibling.nodeType===j.NodeType.TEXT_NODE){c.previousSibling.data=c.previousSibling.data+c.data;c.parentNode.removeChild(c)}}}else{if(H&&D&&(!r._4eSameLevel(H)||!f._4eSameLevel(D))){c=
H._4eIndex();d&&H._4eSameLevel(r)&&c--;a.setStart(H.parent(),c+1)}a.collapse(w)}d&&r.remove();Q&&f.remove();return z}function p(a){a.collapsed=a.startContainer&&a.endContainer&&a.startContainer[0]===a.endContainer[0]&&a.startOffset===a.endOffset}function e(a){this.endOffset=this.endContainer=this.startOffset=this.startContainer=l;this.collapsed=w;this.document=a}b("./dom");var i=b("node"),v=b("./utils"),s=b("./walker"),k=b("./base"),u=b("./elementPath");k.RangeType={POSITION_AFTER_START:1,POSITION_BEFORE_END:2,
POSITION_BEFORE_START:3,POSITION_AFTER_END:4,ENLARGE_ELEMENT:1,ENLARGE_BLOCK_CONTENTS:2,ENLARGE_LIST_ITEM_CONTENTS:3,START:1,END:2,SHRINK_ELEMENT:1,SHRINK_TEXT:2};var w=true,n=false,l=null,d=k.RangeType,c=k.PositionType,j=a.DOM,h=a.UA,f=k.XHTML_DTD,g=i.all,y={td:1},z={area:1,base:1,br:1,col:1,hr:1,img:1,input:1,link:1,meta:1,param:1},q=new s.whitespaces,D=new s.bookmark,B=s.whitespaces(w),I=s.bookmark(false,true),G={abbr:1,acronym:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,
label:1,kbd:1,q:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,"var":1};a.augment(e,{toString:function(){var a=[],b=this.startContainer[0],f=this.endContainer[0];a.push((b.id||b.nodeName)+":"+this.startOffset);a.push((f.id||f.nodeName)+":"+this.endOffset);return a.join("<br/>")},optimize:function(){var a=this.startContainer,b=this.startOffset;a[0].nodeType!==j.NodeType.ELEMENT_NODE&&(b?b>=a[0].nodeValue.length&&this.setStartAfter(a):this.setStartBefore(a));a=this.endContainer;b=this.endOffset;
a[0].nodeType!==j.NodeType.ELEMENT_NODE&&(b?b>=a[0].nodeValue.length&&this.setEndAfter(a):this.setEndBefore(a))},setStartAfter:function(a){this.setStart(a.parent(),a._4eIndex()+1)},setStartBefore:function(a){this.setStart(a.parent(),a._4eIndex())},setEndAfter:function(a){this.setEnd(a.parent(),a._4eIndex()+1)},setEndBefore:function(a){this.setEnd(a.parent(),a._4eIndex())},optimizeBookmark:function(){var a=this.startContainer,b=this.endContainer;a&&a.nodeName()==="span"&&a.attr("_ke_bookmark")&&this.setStartBefore(a);
b&&b.nodeName()==="span"&&b.attr("_ke_bookmark")&&this.setEndAfter(b)},setStart:function(a,b){if(a[0].nodeType===j.NodeType.ELEMENT_NODE&&z[a.nodeName()]){a=a.parent();b=a._4eIndex()}this.startContainer=a;this.startOffset=b;if(!this.endContainer){this.endContainer=a;this.endOffset=b}p(this)},setEnd:function(a,b){if(a[0].nodeType===j.NodeType.ELEMENT_NODE&&z[a.nodeName()]){a=a.parent();b=a._4eIndex()+1}this.endContainer=a;this.endOffset=b;if(!this.startContainer){this.startContainer=a;this.startOffset=
b}p(this)},setStartAt:function(a,b){switch(b){case d.POSITION_AFTER_START:this.setStart(a,0);break;case d.POSITION_BEFORE_END:a[0].nodeType===j.NodeType.TEXT_NODE?this.setStart(a,a[0].nodeValue.length):this.setStart(a,a[0].childNodes.length);break;case d.POSITION_BEFORE_START:this.setStartBefore(a);break;case d.POSITION_AFTER_END:this.setStartAfter(a)}p(this)},setEndAt:function(a,b){switch(b){case d.POSITION_AFTER_START:this.setEnd(a,0);break;case d.POSITION_BEFORE_END:a[0].nodeType===j.NodeType.TEXT_NODE?
this.setEnd(a,a[0].nodeValue.length):this.setEnd(a,a[0].childNodes.length);break;case d.POSITION_BEFORE_START:this.setEndBefore(a);break;case d.POSITION_AFTER_END:this.setEndAfter(a)}p(this)},cloneContents:function(){return x(this,2)},deleteContents:function(){return x(this,0)},extractContents:function(){return x(this,1)},collapse:function(a){if(a){this.endContainer=this.startContainer;this.endOffset=this.startOffset}else{this.startContainer=this.endContainer;this.startOffset=this.endOffset}this.collapsed=
w},clone:function(){var a=new e(this.document);a.startContainer=this.startContainer;a.startOffset=this.startOffset;a.endContainer=this.endContainer;a.endOffset=this.endOffset;a.collapsed=this.collapsed;return a},getEnclosedNode:function(){var a=this.clone();a.optimize();if(a.startContainer[0].nodeType!==j.NodeType.ELEMENT_NODE||a.endContainer[0].nodeType!==j.NodeType.ELEMENT_NODE)return l;var b=new s(a);b.evaluator=function(a){return B(a)&&I(a)};a=b.next();b.reset();b=b.previous();return a&&a.equals(b)?
a:l},shrink:function(a,b){if(!this.collapsed){var a=a||d.SHRINK_TEXT,f=this.clone(),g=this.startContainer,h=this.endContainer,c=this.startOffset,e=this.endOffset,y=w,z,q,i=w;if(g&&g[0].nodeType===j.NodeType.TEXT_NODE)if(c)if(c>=g[0].nodeValue.length)f.setStartAfter(g);else{f.setStartBefore(g);y=n}else f.setStartBefore(g);if(h&&h[0].nodeType===j.NodeType.TEXT_NODE)if(e)if(e>=h[0].nodeValue.length)f.setEndAfter(h);else{f.setEndAfter(h);i=n}else f.setEndBefore(h);if(y||i){q=new s(f);q.evaluator=function(b){return b.nodeType===
(a===d.SHRINK_ELEMENT?j.NodeType.ELEMENT_NODE:j.NodeType.TEXT_NODE)};q.guard=function(b,f){if(a===d.SHRINK_ELEMENT&&b.nodeType===j.NodeType.TEXT_NODE||f&&b===z)return n;!f&&b.nodeType===j.NodeType.ELEMENT_NODE&&(z=b);return w}}if(y)(f=q[a===d.SHRINK_ELEMENT?"lastForward":"next"]())&&this.setStartAt(f,b?d.POSITION_AFTER_START:d.POSITION_BEFORE_START);if(i){q.reset();(q=q[a===d.SHRINK_ELEMENT?"lastBackward":"previous"]())&&this.setEndAt(q,b?d.POSITION_BEFORE_END:d.POSITION_AFTER_END)}return y||i}},
createBookmark2:function(a){var b=this.startContainer,f=this.endContainer,g=this.startOffset,h=this.endOffset,d,c;if(!b||!f)return{start:0,end:0};if(a){if(b[0].nodeType===j.NodeType.ELEMENT_NODE)if((d=new i(b[0].childNodes[g]))&&d[0]&&d[0].nodeType===j.NodeType.TEXT_NODE&&g>0&&d[0].previousSibling.nodeType===j.NodeType.TEXT_NODE){b=d;g=0}for(;b[0].nodeType===j.NodeType.TEXT_NODE&&(c=b.prev(void 0,1))&&c[0].nodeType===j.NodeType.TEXT_NODE;){b=c;g=g+c[0].nodeValue.length}if(!this.collapsed){if(f[0].nodeType===
j.NodeType.ELEMENT_NODE)if((d=new i(f[0].childNodes[h]))&&d[0]&&d[0].nodeType===j.NodeType.TEXT_NODE&&h>0&&d[0].previousSibling.nodeType===j.NodeType.TEXT_NODE){f=d;h=0}for(;f[0].nodeType===j.NodeType.TEXT_NODE&&(c=f.prev(void 0,1))&&c[0].nodeType===j.NodeType.TEXT_NODE;){f=c;h=h+c[0].nodeValue.length}}}return{start:b._4eAddress(a),end:this.collapsed?l:f._4eAddress(a),startOffset:g,endOffset:h,normalized:a,is2:w}},createBookmark:function(b){var f,r,g,h,c=this.collapsed;f=new i("<span>",l,this.document);
f.attr("_ke_bookmark",1);f.css("display","none");f.html("&nbsp;");if(b){g=a.guid("ke_bm_");f.attr("id",g+"S")}if(!c){r=f.clone();r.html("&nbsp;");b&&r.attr("id",g+"E");h=this.clone();h.collapse();h.insertNode(r)}h=this.clone();h.collapse(w);h.insertNode(f);if(r){this.setStartAfter(f);this.setEndBefore(r)}else this.moveToPosition(f,d.POSITION_AFTER_END);return{startNode:b?g+"S":f,endNode:b?g+"E":r,serializable:b,collapsed:c}},moveToPosition:function(a,b){this.setStartAt(a,b);this.collapse(w)},trim:function(a,
b){var f=this.startContainer,g=this.startOffset,h=this.collapsed;if((!a||h)&&f[0]&&f[0].nodeType===j.NodeType.TEXT_NODE){if(g)if(g>=f[0].nodeValue.length){g=f._4eIndex()+1;f=f.parent()}else{var d=f._4eSplitText(g),g=f._4eIndex()+1,f=f.parent();if(j.equals(this.startContainer,this.endContainer))this.setEnd(d,this.endOffset-this.startOffset);else if(j.equals(f,this.endContainer))this.endOffset=this.endOffset+1}else{g=f._4eIndex();f=f.parent()}this.setStart(f,g);if(h){this.collapse(w);return}}f=this.endContainer;
g=this.endOffset;if(!b&&!h&&f[0]&&f[0].nodeType===j.NodeType.TEXT_NODE){if(g){g>=f[0].nodeValue.length||f._4eSplitText(g);g=f._4eIndex()+1}else g=f._4eIndex();f=f.parent();this.setEnd(f,g)}},insertNode:function(a){this.optimizeBookmark();this.trim(n,w);var b=this.startContainer;b[0].insertBefore(a[0],b[0].childNodes[this.startOffset]||null);b[0]===this.endContainer[0]&&this.endOffset++;this.setStartBefore(a)},moveToBookmark:function(b){var f=g(this.document);if(b.is2){var r=f._4eGetByAddress(b.start,
b.normalized),h=b.startOffset,f=b.end&&f._4eGetByAddress(b.end,b.normalized),b=b.endOffset;this.setStart(r,h);f?this.setEnd(f,b):this.collapse(w)}else{r=(h=b.serializable)?a.one("#"+b.startNode,f):b.startNode;b=h?a.one("#"+b.endNode,f):b.endNode;this.setStartBefore(r);r._4eRemove();if(b&&b[0]){this.setEndBefore(b);b._4eRemove()}else this.collapse(w)}},getCommonAncestor:function(a,b){var f=this.startContainer,g=this.endContainer,f=f[0]===g[0]?a&&f[0].nodeType===j.NodeType.ELEMENT_NODE&&this.startOffset===
this.endOffset-1?new i(f[0].childNodes[this.startOffset]):f:f._4eCommonAncestor(g);return b&&f[0].nodeType===j.NodeType.TEXT_NODE?f.parent():f},enlarge:function(){function a(b,f,h,d){var c=b[f?"startContainer":"endContainer"],e,y=f?0:1,z=0,i=f?"previousSibling":"nextSibling";e=b[f?"startOffset":"endOffset"];if(c[0].nodeType===j.NodeType.TEXT_NODE){if(f){if(e)return}else if(e<c[0].nodeValue.length)return;e=c[0][i];c=c[0].parentNode}else{e=c[0].childNodes[e+(f?-1:1)]||null;c=c[0]}for(;c;){for(;e;)if(q(e)||
D(e))e=e[i];else break;if(e){if(!z)b[f?"setStartAfter":"setEndBefore"](g(e));break}c=g(c);if(c.nodeName()==="body")break;if(z||c.equals(d)){h[y]=c;z=1}else b[f?"setStartBefore":"setEndAfter"](c);e=c[0][i];c=c[0].parentNode}}return function(b){var f;switch(b){case d.ENLARGE_ELEMENT:if(this.collapsed)break;var b=this.getCommonAncestor(),h=[];a(this,1,h,b);a(this,0,h,b);if(h[0]&&h[1]){b=h[0].contains(h[1])?h[1]:h[0];this.setStartBefore(b);this.setEndAfter(b)}break;case d.ENLARGE_BLOCK_CONTENTS:case d.ENLARGE_LIST_ITEM_CONTENTS:f=
new e(this.document);h=new i(this.document.body);f.setStartAt(h,d.POSITION_AFTER_START);f.setEnd(this.startContainer,this.startOffset);f=new s(f);var c,y,z=s.blockBoundary(b===d.ENLARGE_LIST_ITEM_CONTENTS?{br:1}:l),q=function(a){var b=z(a);b||(c=g(a));return b},n=function(a){var b=q(a);!b&&j.nodeName(a)==="br"&&(y=g(a));return b};f.guard=q;f=f.lastBackward();c=c||h;this.setStartAt(c,c.nodeName()!=="br"&&(!f&&this.checkStartOfBlock()||f&&c.contains(f))?d.POSITION_AFTER_START:d.POSITION_AFTER_END);
f=this.clone();f.collapse();f.setEndAt(h,d.POSITION_BEFORE_END);f=new s(f);f.guard=b===d.ENLARGE_LIST_ITEM_CONTENTS?n:q;c=l;f=f.lastForward();c=c||h;this.setEndAt(c,!f&&this.checkEndOfBlock()||f&&c.contains(f)?d.POSITION_BEFORE_END:d.POSITION_BEFORE_START);y&&this.setEndAfter(y)}}}(),checkStartOfBlock:function(){var b=this.startContainer,f=this.startOffset;if(f&&b[0].nodeType===j.NodeType.TEXT_NODE&&a.trim(b[0].nodeValue.substring(0,f)).length)return n;this.trim();b=new u(this.startContainer);f=this.clone();
f.collapse(w);f.setStartAt(b.block||b.blockLimit,d.POSITION_AFTER_START);b=new s(f);b.evaluator=m(w);return b.checkBackward()},checkEndOfBlock:function(){var b=this.endContainer,f=this.endOffset;if(b[0].nodeType===j.NodeType.TEXT_NODE&&a.trim(b[0].nodeValue.substring(f)).length)return n;this.trim();b=new u(this.endContainer);f=this.clone();f.collapse(n);f.setEndAt(b.block||b.blockLimit,d.POSITION_BEFORE_END);b=new s(f);b.evaluator=m(n);return b.checkForward()},checkBoundaryOfElement:function(a,b){var f=
this.clone();f[b===d.START?"setStartAt":"setEndAt"](a,b===d.START?d.POSITION_AFTER_START:d.POSITION_BEFORE_END);f=new s(f);f.evaluator=o;return f[b===d.START?"checkBackward":"checkForward"]()},getBoundaryNodes:function(){var a=this.startContainer,b=this.endContainer,f=this.startOffset,h=this.endOffset,d;if(a[0].nodeType===j.NodeType.ELEMENT_NODE){d=a[0].childNodes.length;if(d>f)a=g(a[0].childNodes[f]);else if(d===0)a=a._4ePreviousSourceNode();else{for(a=a[0];a.lastChild;)a=a.lastChild;a=g(a);a=a._4eNextSourceNode()||
a}}if(b[0].nodeType===j.NodeType.ELEMENT_NODE){d=b[0].childNodes.length;if(d>h)b=g(b[0].childNodes[h])._4ePreviousSourceNode(w);else if(d===0)b=b._4ePreviousSourceNode();else{for(b=b[0];b.lastChild;)b=b.lastChild;b=g(b)}}a._4ePosition(b)&c.POSITION_FOLLOWING&&(a=b);return{startNode:a,endNode:b}},fixBlock:function(a,b){var f=this.createBookmark(),c=g(this.document.createElement(b));this.collapse(a);this.enlarge(d.ENLARGE_BLOCK_CONTENTS);c[0].appendChild(this.extractContents());c._4eTrim();h.ie||c._4eAppendBogus();
this.insertNode(c);this.moveToBookmark(f);return c},splitBlock:function(b){var f=new u(this.startContainer),g=new u(this.endContainer),c=f.block,e=g.block,y=l;if(!f.blockLimit.equals(g.blockLimit))return l;if(b!=="br"){if(!c){c=this.fixBlock(w,b);e=(new u(this.endContainer)).block}e||(e=this.fixBlock(n,b))}b=c&&this.checkStartOfBlock();f=e&&this.checkEndOfBlock();this.deleteContents();if(c&&c[0]===e[0])if(f){y=new u(this.startContainer);this.moveToPosition(e,d.POSITION_AFTER_END);e=l}else if(b){y=
new u(this.startContainer);this.moveToPosition(c,d.POSITION_BEFORE_START);c=l}else{e=this.splitElement(c);!h.ie&&!a.inArray(c.nodeName(),["ul","ol"])&&c._4eAppendBogus()}return{previousBlock:c,nextBlock:e,wasStartOfBlock:b,wasEndOfBlock:f,elementPath:y}},splitElement:function(a){if(!this.collapsed)return l;this.setEndAt(a,d.POSITION_BEFORE_END);var b=this.extractContents(),f=a.clone(n);f[0].appendChild(b);f.insertAfter(a);this.moveToPosition(a,d.POSITION_AFTER_END);return f},moveToElementEditablePosition:function(a,
b){for(var f=0;a;){if(a[0].nodeType===j.NodeType.TEXT_NODE){this.moveToPosition(a,b?d.POSITION_AFTER_END:d.POSITION_BEFORE_START);f=1;break}if(a[0].nodeType===j.NodeType.ELEMENT_NODE&&a._4eIsEditable()){this.moveToPosition(a,b?d.POSITION_BEFORE_END:d.POSITION_AFTER_START);f=1}var g=a,h=f,c=void 0;g[0].nodeType===j.NodeType.ELEMENT_NODE&&g._4eIsEditable()&&(c=g[b?"last":"first"](t,1));!h&&!c&&(c=g[b?"prev":"next"](t,1));a=c}return!!f},selectNodeContents:function(a){var b=a[0];this.setStart(a,0);this.setEnd(a,
b.nodeType===j.NodeType.TEXT_NODE?b.nodeValue.length:b.childNodes.length)},insertNodeByDtd:function(a){var b,g,h,c=a.nodeName();b=f.$block[c];this.deleteContents();if(b){for(b=this.getCommonAncestor(n,w);(g=f[b.nodeName()])&&(!g||!g[c]);){var d=b.parent();if(this.checkStartOfBlock()&&this.checkEndOfBlock()){this.setStartBefore(b);this.collapse(w);b.remove()}else h=b;b=d}h&&this.splitElement(h)}this.insertNode(a)}});v.injectDom({_4eBreakParent:function(a,b){var b=g(b),a=g(a),f,h=new k.Range(a[0].ownerDocument);
h.setStartAfter(a);h.setEndAfter(b);f=h.extractContents();h.insertNode(a.remove());a.after(f)}});return k.Range=e});
KISSY.add("editor/selection",["node","./walker","./range","./base"],function(a,b){function o(a){this.document=a;this._={cache:{}};if(n)try{var b=this.getNative().createRange();if(!b||b.item&&b.item(0).ownerDocument!==a||b.parentElement&&b.parentElement().ownerDocument!==a)this.isInvalid=i}catch(g){this.isInvalid=i}}function t(a){a=new o(a);return!a||a.isInvalid?v:a}var m=b("node"),x=b("./walker"),p=b("./range"),e=b("./base");e.SelectionType={SELECTION_NONE:1,SELECTION_TEXT:2,SELECTION_ELEMENT:3};
var i=!0,v=null,s=a.UA,k=a.DOM,u=e.SelectionType,w=e.RangeType,n=document.selection,l={img:1,hr:1,li:1,table:1,tr:1,td:1,th:1,embed:1,object:1,ol:1,ul:1,a:1,input:1,form:1,select:1,textarea:1,button:1,fieldset:1,thead:1,tfoot:1};a.augment(o,{getNative:!n?function(){var a=this._.cache;return a.nativeSel||(a.nativeSel=k.getWindow(this.document).getSelection())}:function(){var a=this._.cache;return a.nativeSel||(a.nativeSel=this.document.selection)},getType:!n?function(){var a=this._.cache;if(a.type)return a.type;
var b=u.SELECTION_TEXT,g=this.getNative();if(g){if(1===g.rangeCount){var g=g.getRangeAt(0),c=g.startContainer;c===g.endContainer&&c.nodeType===k.NodeType.ELEMENT_NODE&&1===Number(g.endOffset-g.startOffset)&&l[c.childNodes[g.startOffset].nodeName.toLowerCase()]&&(b=u.SELECTION_ELEMENT)}}else b=u.SELECTION_NONE;return a.type=b}:function(){var a=this._.cache;if(a.type)return a.type;var b=u.SELECTION_NONE;try{var g=this.getNative(),c=g.type;"Text"===c&&(b=u.SELECTION_TEXT);"Control"===c&&(b=u.SELECTION_ELEMENT);
g.createRange().parentElement&&(b=u.SELECTION_TEXT)}catch(d){}return a.type=b},getRanges:n?function(){var a=function(a,b){a=a.duplicate();a.collapse(b);for(var c=a.parentElement(),h=c.childNodes,d,e=0;e<h.length;e++){var i=h[e];if(i.nodeType===k.NodeType.ELEMENT_NODE){d=a.duplicate();d.moveToElementText(i);var i=d.compareEndPoints("StartToStart",a),l=d.compareEndPoints("EndToStart",a);d.collapse();if(0<i)break;else{if(!i||1===l&&-1===i)return{container:c,offset:e};if(!l)return{container:c,offset:e+
1}}d=v}}d||(d=a.duplicate(),d.moveToElementText(c),d.collapse(!1));d.setEndPoint("StartToStart",a);d=(""+d.text).replace(/\r\n|\r/g,"\n").length;try{for(;0<d;)d-=h[--e].nodeValue.length}catch(j){d=0}return 0===d?{container:c,offset:e}:{container:h[e],offset:-d}};return function(b){var g=this._.cache;if(g.ranges&&!b)return g.ranges;var c=this.getNative(),b=c&&c.createRange(),d=this.getType();if(!c)return[];if(d===u.SELECTION_TEXT)return c=new p(this.document),d=a(b,i),c.setStart(new m(d.container),
d.offset),d=a(b),c.setEnd(new m(d.container),d.offset),g.ranges=[c],[c];if(d===u.SELECTION_ELEMENT){g=g.ranges=[];for(d=0;d<b.length;d++){for(var e=b.item(d),l=e.parentNode,j=0,c=new p(this.document);j<l.childNodes.length&&l.childNodes[j]!==e;j++);c.setStart(new m(l),j);c.setEnd(new m(l),j+1);g.push(c)}return g}g.ranges=[];return[]}}():function(a){var b=this._.cache;if(b.ranges&&!a)return b.ranges;var a=[],g=this.getNative();if(!g)return[];for(var c=0;c<g.rangeCount;c++){var d=g.getRangeAt(c),e=new p(this.document);
e.setStart(new m(d.startContainer),d.startOffset);e.setEnd(new m(d.endContainer),d.endOffset);a.push(e)}return b.ranges=a},getStartElement:function(){var a=this._.cache;if(void 0!==a.startElement)return a.startElement;var b,g=this.getNative();switch(this.getType()){case u.SELECTION_ELEMENT:return this.getSelectedElement();case u.SELECTION_TEXT:var c=this.getRanges()[0];if(c&&!c.collapsed){for(c.optimize();i;)if(b=c.startContainer,c.startOffset===(b[0].nodeType===k.NodeType.ELEMENT_NODE?b[0].childNodes.length:
b[0].nodeValue.length)&&!b._4eIsBlockBoundary())c.setStartAfter(b);else break;b=c.startContainer;if(b[0].nodeType!==k.NodeType.ELEMENT_NODE)return b.parent();b=new m(b[0].childNodes[c.startOffset]);if(!b[0]||b[0].nodeType!==k.NodeType.ELEMENT_NODE)return c.startContainer;for(c=b[0].firstChild;c&&c.nodeType===k.NodeType.ELEMENT_NODE;)b=new m(c),c=c.firstChild;return b}if(n)c=g.createRange(),c.collapse(i),b=new m(c.parentElement());else{if((b=g.anchorNode)&&b.nodeType!==k.NodeType.ELEMENT_NODE)b=b.parentNode;
b&&(b=new m(b))}}return a.startElement=b},getSelectedElement:function(){var a,b=this._.cache;if(void 0!==b.selectedElement)return b.selectedElement;n&&(a=this.getNative().createRange(),a=a.item&&a.item(0));var c;if(a)c=new m(a);else{a=this.getRanges()[0];for(var d,e=2;e&&(!(c=a.getEnclosedNode())||!(c[0].nodeType===k.NodeType.ELEMENT_NODE&&l[c.nodeName()]&&(d=c)));e--)a.shrink(w.SHRINK_ELEMENT);c=d}a=c;return b.selectedElement=a},reset:function(){this._.cache={}},selectElement:function(a){var b,c=
this.document;if(n)try{b=c.body.createControlRange(),b.addElement(a[0]),b.select()}catch(d){b=c.body.createTextRange(),b.moveToElementText(a[0]),b.select()}finally{}else b=c.createRange(),b.selectNode(a[0]),a=this.getNative(),a.removeAllRanges(),a.addRange(b);this.reset()},selectRanges:function(a){if(n){if(1<a.length){var b=a[a.length-1];a[0].setEnd(b.endContainer,b.endOffset);a.length=1}a[0]&&a[0].select()}else{b=this.getNative();if(!b)return;b.removeAllRanges();for(var c=0;c<a.length;c++){var d=
a[c],e=this.document.createRange(),i=d.startContainer;if(d.collapsed&&(s.gecko&&1.09>s.gecko||s.opera||s.webkit)&&i[0].nodeType===k.NodeType.ELEMENT_NODE&&!i[0].childNodes.length)i[0].appendChild(this.document.createTextNode(s.webkit?"\u200b":"")),d.startOffset++,d.endOffset++;e.setStart(i[0],d.startOffset);e.setEnd(d.endContainer[0],d.endOffset);b.addRange(e)}}this.reset()},createBookmarks2:function(a){for(var b=[],c=this.getRanges(),d=0;d<c.length;d++)b.push(c[d].createBookmark2(a));return b},createBookmarks:function(b,
f){for(var c=[],d=this.document,e,f=f||this.getRanges(),l=f.length,j=0;j<l;j++){c.push(e=f[j].createBookmark(b,i));var n=(b=e.serializable)?a.one("#"+e.startNode,d):e.startNode;e=b?a.one("#"+e.endNode,d):e.endNode;for(var o=j+1;o<l;o++){var m=f[o],p=m.startContainer,s=m.endContainer;k.equals(p,n.parent())&&m.startOffset++;k.equals(p,e.parent())&&m.startOffset++;k.equals(s,n.parent())&&m.endOffset++;k.equals(s,e.parent())&&m.endOffset++}}return c},selectBookmarks:function(a){for(var b=[],c=0;c<a.length;c++){var d=
new p(this.document);d.moveToBookmark(a[c]);b.push(d)}this.selectRanges(b);return this},getCommonAncestor:function(){var a=this.getRanges();return a[0].startContainer._4eCommonAncestor(a[a.length-1].endContainer)},scrollIntoView:function(){var a=this.getStartElement();a&&a.scrollIntoView(void 0,{alignWithTop:!1,allowHorizontalScroll:!0,onlyScrollIfNeeded:!0})},removeAllRanges:function(){var a=this.getNative();n?a&&a.clear():a&&a.removeAllRanges()}});var d={table:1,tbody:1,tr:1},c=x.whitespaces(i),
j=/\ufeff|\u00a0/;p.prototype.select=!n?function(){var a=this.startContainer;this.collapsed&&a[0].nodeType===k.NodeType.ELEMENT_NODE&&!a[0].childNodes.length&&(a[0].appendChild(this.document.createTextNode(s.webkit?"\u200b":"")),this.startOffset++,this.endOffset++);var b=this.document.createRange();b.setStart(a[0],this.startOffset);try{b.setEnd(this.endContainer[0],this.endOffset)}catch(c){if(0<=c.toString().indexOf("NS_ERROR_ILLEGAL_VALUE"))this.collapse(i),b.setEnd(this.endContainer[0],this.endOffset);
else throw c;}a=t(this.document).getNative();a.removeAllRanges();a.addRange(b)}:function(a){var b=this.collapsed,g,e;if(this.startContainer[0]===this.endContainer[0]&&1===this.endOffset-this.startOffset){var l=this.startContainer[0].childNodes[this.startOffset];if(l.nodeType===k.NodeType.ELEMENT_NODE){(new o(this.document)).selectElement(new m(l));return}}(this.startContainer[0].nodeType===k.NodeType.ELEMENT_NODE&&this.startContainer.nodeName()in d||this.endContainer[0].nodeType===k.NodeType.ELEMENT_NODE&&
this.endContainer.nodeName()in d)&&this.shrink(w.SHRINK_ELEMENT,i);var q=this.createBookmark(),l=q.startNode,n;b||(n=q.endNode);q=this.document.body.createTextRange();q.moveToElementText(l[0]);q.moveStart("character",1);if(n)a=this.document.body.createTextRange(),a.moveToElementText(n[0]),q.setEndPoint("EndToEnd",a),q.moveEnd("character",-1);else{for(g=l[0].nextSibling;g&&!c(g);)g=g.nextSibling;g=!(g&&g.nodeValue&&g.nodeValue.match(j))&&(a||!l[0].previousSibling||l[0].previousSibling&&"br"===k.nodeName(l[0].previousSibling));
e=new m(this.document.createElement("span"));e.html("&#65279;");e.insertBefore(l);g&&k.insertBefore(this.document.createTextNode("\ufeff"),l[0]||l)}this.setStartBefore(l);l._4eRemove();if(b){if(g?(q.moveStart("character",-1),q.select(),this.document.selection.clear()):q.select(),e)this.moveToPosition(e,w.POSITION_BEFORE_START),e._4eRemove()}else this.setEndBefore(n),n._4eRemove(),q.select()};o.getSelection=t;return e.Selection=o});
KISSY.add("editor/clipboard",["node","./base","./range","./selection"],function(a,b){function o(a){this.editor=a;this._init()}function t(a){var b=a.get("document")[0],c=a.getSelection(),d;if(c.getType()===s.SELECTION_ELEMENT&&(d=c.getSelectedElement())){var a=c.getRanges()[0],e=k(b.createTextNode(""));e.insertBefore(d);a.setStartBefore(e);a.setEndAfter(d);c.selectRanges([a]);setTimeout(function(){d.parent()&&(e.remove(),c.selectElement(d))},0)}}function m(a){if(u.webkit){if(!a.match(/^[^<]*$/g)&&
!a.match(/^(<div><br( ?\/)?><\/div>|<div>[^<]*<\/div>)*$/gi))return 0}else if(u.ie){if(!a.match(/^([^<]|<br( ?\/)?>)*$/gi)&&!a.match(/^(<p>([^<]|<br( ?\/)?>)*<\/p>|(\r\n))*$/gi))return 0}else if(u.gecko||u.opera){if(!a.match(/^([^<]|<br( ?\/)?>)*$/gi))return 0}else return 0;return 1}function x(a){a=a.replace(/\s+/g," ").replace(/> +</g,"><").replace(/<br ?\/>/gi,"<br>");if(a.match(/^[^<]$/))return a;if(u.webkit&&-1<a.indexOf("<div>"))a.match(/<div>(?:<br>)?<\/div>/)&&(a=a.replace(/<div>(?:<br>)?<\/div>/g,
function(){return"<p></p>"}),a=a.replace(/<\/p><div>/g,"</p><p>").replace(/<\/div><p>/g,"</p><p>").replace(/^<div>/,"<p>").replace(/^<\/div>/,"</p>")),a.match(/<\/div><div>/)&&(a=a.replace(/<\/div><div>/g,"</p><p>").replace(/^<div>/,"<p>").replace(/^<\/div>/,"</p>"));else if(u.gecko||u.opera)u.gecko&&(a=a.replace(/^<br><br>$/,"<br>")),-1<a.indexOf("<br><br>")&&(a="<p>"+a.replace(/<br><br>/g,function(){return"</p><p>"})+"</p>");return a}function p(a){var b=0,a=a.replace(/<span[^>]+_ke_bookmark[^<]*?<\/span>(&nbsp;)*/ig,
"");-1!==a.indexOf("Apple-")&&(a=a.replace(/<span class="Apple-converted-space">&nbsp;<\/span>/gi," "),a=a.replace(/<span class="Apple-tab-span"[^>]*>([^<]*)<\/span>/gi,function(a,b){return b.replace(/\t/g,Array(5).join("&nbsp;"))}),-1<a.indexOf('<br class="Apple-interchange-newline">')&&(b=1,a=a.replace(/<br class="Apple-interchange-newline">/,"")),a=a.replace(/(<[^>]+) class="Apple-[^"]*"/gi,"$1"));!b&&m(a)&&(a=x(a));return a}var e=b("node"),i=b("./base"),v=b("./range"),s=b("./selection"),k=e.all,
u=a.UA,w=11>u.ieMode,n=w?"beforepaste":"paste",l=i.RangeType;a.augment(o,{_init:function(){var a=this,b=a.editor,d=b.get("document"),e=d.one("body"),h=function(a){this.type=a};h.prototype={exec:function(b){var d=this.type;b.focus();setTimeout(function(){w&&("cut"===d?t(b):"paste"===d&&(a._preventPasteEvent(),a._getClipboardDataFromPasteBin()));c(b,d)||alert(j[d])},0)}};e.on(n,a._getClipboardDataFromPasteBin,a);w&&(e.on("paste",a._iePaste,a),d.on("keydown",a._onKeyDown,a),d.on("contextmenu",function(){a._isPreventBeforePaste=
1;setTimeout(function(){a._isPreventBeforePaste=0},0)}));b.addCommand("copy",new h("copy"));b.addCommand("cut",new h("cut"));b.addCommand("paste",new h("paste"))},_onKeyDown:function(a){this.editor.get("mode")===i.Mode.WYSIWYG_MODE&&(a.ctrlKey&&86===a.keyCode||a.shiftKey&&45===a.keyCode)&&this._preventPasteEvent()},_stateFromNamedCommand:function(a){var b,c=this.editor;if("paste"===a){this._isPreventBeforePaste=1;try{b=c.get("document")[0].queryCommandEnabled(a)}catch(d){}this._isPreventBeforePaste=
0}else b=(a=(a=c.getSelection())&&a.getRanges())&&!(1===a.length&&a[0].collapsed);return b},_preventPasteEvent:function(){var a=this;a._preventPasteTimer&&clearTimeout(a._preventPasteTimer);a._isPreventPaste=1;a._preventPasteTimer=setTimeout(function(){a._isPreventPaste=0},70)},_iePaste:function(a){var b=this.editor;this._isPreventPaste||(a.preventDefault(),b.execCommand("paste"))},_getClipboardDataFromPasteBin:function(){if(!this._isPreventBeforePaste){var b=this.editor,c=b.get("document")[0];if(!c.getElementById("ke-paste-bin")){var d=
b.getSelection(),e=new v(c),h=k(u.webkit?"<body></body>":"<div></div>",c);h.attr("id","ke-paste-bin");u.webkit&&h[0].appendChild(c.createTextNode("\u200b"));c.body.appendChild(h[0]);h.css({position:"absolute",top:d.getStartElement().offset().top+"px",width:"1px",height:"1px",overflow:"hidden"});h.css("left","-1000px");var i=d.createBookmarks();e.setStartAt(h,l.POSITION_AFTER_START);e.setEndAt(h,l.POSITION_BEFORE_END);e.select(!0);setTimeout(function(){var c,e=h;h=u.webkit&&(c=h.first())&&c.hasClass("Apple-style-span")?
c:h;d.selectBookmarks(i);var g=h.html();e.remove();if(g=p(g))c=b.fire("paste",{html:g}),!1!==c&&(void 0!==c&&(g=c),/(class="?Mso|style="[^"]*\bmso\-|w:WordDocument)/.test(g)?a.use("editor/plugin/word-filter",function(a,c){b.insertHtml(c.toDataFormat(g,b))}):b.insertHtml(g))},0)}}}});var d=function(a,b){var c=a.get("document")[0],d=k(c.body),e=!1,h=function(){e=!0};d.on(b,h);(7<u.ieMode?c:c.selection.createRange()).execCommand(b);d.detach(b,h);return e},c=w?function(a,b){return d(a,b)}:function(a,
b){try{return a.get("document")[0].execCommand(b)}catch(c){return!1}},j={cut:"\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u7f16\u8f91\u5668\u81ea\u52a8\u6267\u884c\u526a\u5207\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl/Cmd+X)\u6765\u5b8c\u6210",copy:"\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u7f16\u8f91\u5668\u81ea\u52a8\u6267\u884c\u590d\u5236\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl/Cmd+C)\u6765\u5b8c\u6210",paste:"\u60a8\u7684\u6d4f\u89c8\u5668\u5b89\u5168\u8bbe\u7f6e\u4e0d\u5141\u8bb8\u7f16\u8f91\u5668\u81ea\u52a8\u6267\u884c\u7c98\u8d34\u64cd\u4f5c\uff0c\u8bf7\u4f7f\u7528\u952e\u76d8\u5feb\u6377\u952e(Ctrl/Cmd+V)\u6765\u5b8c\u6210"},h={copy:"\u590d\u5236",paste:"\u7c98\u8d34",cut:"\u526a\u5207"};return{init:function(a){var b;a.docReady(function(){b=new o(a)});var c={copy:1,cut:1,paste:1},d=["copy","cut","paste"];a.on("contextmenu",function(e){var i=e.contextmenu;if(!i.__copyFix){i.__copyFix=1;for(e=0;e<d.length;e++)i.addChild({content:h[d[e]],
value:d[e]});i.on("click",function(b){var d=b.target.get("value");c[d]&&(i.hide(),setTimeout(function(){a.execCommand("save");a.execCommand(d);setTimeout(function(){a.execCommand("save")},10)},30))})}for(var l=i.get("children"),e=l.length-1;e--;0<=e){var j=l[e],n;n=j.get?j.get("value"):j.value;c[n]&&(n=!b._stateFromNamedCommand(n),j.set?j.set("disabled",n):j.disabled=n)}})}}});
KISSY.add("editor/enterKey",["node","ua","./walker","./base","./elementPath"],function(a,b){function o(a){var b;b=a.getSelection().getRanges();for(var d=b.length-1;0<d;d--)b[d].deleteContents();b=b[0];var d=b.document,c=new s(b.startContainer),j=b.checkStartOfBlock(),h=b.checkEndOfBlock(),c=c.block;if(j&&h){if(c&&("li"===c.nodeName()||"li"===c.parent().nodeName()))return a.hasCommand("outdent")?(a.execCommand("save"),a.execCommand("outdent"),a.execCommand("save"),!0):!1}else if(c&&"pre"===c.nodeName()&&
!h){var f=9>e.ieMode?p(d.createTextNode("\r")):p(d.createElement("br"));b.insertNode(f);9>e.ieMode?(f=p(d.createTextNode("\ufeff")).insertAfter(f),b.setStartAt(f,v.RangeType.POSITION_AFTER_START)):b.setStartAfter(f);b.collapse(!0);b.select();9>e.ieMode&&(f[0].nodeValue="");return}var g=b.splitBlock("p");if(!g)return!0;var a=g.previousBlock,c=g.nextBlock,j=g.wasStartOfBlock,h=g.wasEndOfBlock,y;if(c)y=c.parent(),"li"===y.nodeName()&&(c._4eBreakParent(y),c._4eMove(c.next(),!0));else if(a&&(y=a.parent())&&
"li"===y.nodeName())a._4eBreakParent(y),b.moveToElementEditablePosition(a.next()),a._4eMove(a.prev());if(!j&&!h){if("li"===c.nodeName()&&(y=c.first(i.invisible(!0)))&&m.inArray(y.nodeName(),["ul","ol"]))(k?new x(d.createTextNode("\u00a0")):new x(d.createElement("br"))).insertBefore(y);c&&b.moveToElementEditablePosition(c)}else{if(a){if("li"===a.nodeName()||!u.test(a.nodeName()))f=a.clone()}else c&&(f=c.clone());f||(f=new x("<p>",null,d));if(y=g.elementPath)for(var g=0,z=y.elements.length;g<z;g++){var q=
y.elements[g];if(q.equals(y.block)||q.equals(y.blockLimit))break;w.$removeEmpty[q.nodeName()]&&(q=q.clone(),f._4eMoveChildren(q),f.append(q))}k||f._4eAppendBogus();b.insertNode(f);if(k&&j&&(!h||!a[0].childNodes.length))b.moveToElementEditablePosition(h?a:f),b.select();b.moveToElementEditablePosition(j&&!h?c:f)}k||(c?(f=new x(d.createElement("span")),f.html("&nbsp;"),b.insertNode(f),f.scrollIntoView(void 0,{alignWithTop:!1,allowHorizontalScroll:!0,onlyScrollIfNeeded:!0}),b.deleteContents()):f.scrollIntoView(void 0,
{alignWithTop:!1,allowHorizontalScroll:!0,onlyScrollIfNeeded:!0}));b.select();return!0}function t(a){a.get("document").on("keydown",function(b){if(13===b.keyCode&&!b.shiftKey&&!b.ctrlKey&&!b.metaKey){a.execCommand("save");var d=a.execCommand("enterBlock");a.execCommand("save");!1!==d&&b.preventDefault()}})}var m=a,x=b("node"),p=x.all,e=b("ua"),i=b("./walker"),v=b("./base"),s=b("./elementPath"),k=11>e.ieMode,u=/^(?:h[1-6])|(?:pre)$/i,w=v.XHTML_DTD;return{init:function(a){a.addCommand("enterBlock",
{exec:o});a.docReady(function(){t(a)})}}});
KISSY.add("editor/htmlDataProcessor",["html-parser","ua","node"],function(a,b){function o(a){if(!e.$removeEmpty[a.nodeName])return!1;var a=a.childNodes,b,m,p=a.length;if(p)for(b=0;b<p;b++)if(m=a[b],m.nodeType!==i.TEXT_NODE||m.nodeValue||!o(m))return!1;return!0}var t=b("html-parser"),m=b("ua"),x=11>m.ieMode,p=b("node"),e=t.DTD,i=p.NodeType,v=a;return{init:function(a){function b(a){return!o(a)}function i(a){return a.replace(c,function(a,b,c){return"<"+b+c.replace(j,function(a,b){return-1===c.indexOf("_keSaved_"+
b)?" _keSaved_"+a+" "+a:a})+">"})}function w(a){return a.replace(f,function(a){return"<ke:encoded>"+encodeURIComponent(a)+"</ke:encoded>"})}function n(a){return a.replace(g,function(a,b){return v.urlDecode(b)})}var l=new t.Filter,d=new t.Filter;(function(){function a(b){b=t.serialize(b);return new t.Comment(h+encodeURIComponent(b).replace(/--/g,"%2D%2D"))}var c={tagNames:[[/^\?xml.*$/i,""],[/^.*namespace.*$/i,""]],attributeNames:[[/^on/,"ke_on"],[/^lang$/,""]],tags:{script:a,noscript:a,span:b}},f=
{tagNames:[[/^ke:/,""],[/^\?xml:namespace$/,""]],tags:{$:function(a){if(a.attributes.length)for(var b=["name","href","src"],c,d=0;d<b.length;d++)c="_keSaved_"+b[d],a.getAttribute(c)&&a.removeAttribute(b[d]);return a},embed:function(a){var b=a.parentNode;if(b&&"object"===b.nodeName){var c=b.getAttribute("width"),b=b.getAttribute("height");c&&a.setAttribute("width",c);b&&a.setAttribute("width",b)}},a:function(a){if(!a.childNodes.length&&!a.attributes.length)return!1},span:b,strong:b,em:b,del:b,u:b},
attributes:{style:function(a){if(!v.trim(a))return!1}},attributeNames:[[/^_keSaved_/,""],[/^ke_on/,"on"],[/^_ke.*/,""],[/^ke:.*$/,""],[/^_ks.*/,""]],comment:function(a){if(a.substr(0,h.length)===h)return a=v.trim(v.urlDecode(a.substr(h.length))),t.parse(a).childNodes[0]}};x&&(f.attributes.style=function(a){return a.replace(/(^|;)([^:]+)/g,function(a){return a.toLowerCase()})});l.addRules(f);d.addRules(c)})();(function(){function a(b){for(var b=b.childNodes,c=b.length,d=b[c-1];d&&(3===d.nodeType&&
!v.trim(d.nodeValue)||1===d.nodeType&&o(d));)d=b[--c];return d}function b(c){var d=a(c);d&&(1===d.nodeType&&"br"===d.nodeName?c.removeChild(d):3===d.nodeType&&h.test(d.nodeValue)&&c.removeChild(d))}function c(b){var d=a(b);return!d||"form"===b.nodeName&&"input"===d.nodeName}function f(a){b(a);c(a)&&(x||a.appendChild(new t.Tag("br")))}function g(a){b(a);c(a)&&a.appendChild(new t.Text("\u00a0"))}var h=/^[\t\r\n ]*(?:&nbsp;|\xa0)[\t\r\n ]*$/,r=v.merge(e.$block,e.$listItem,e.$tableContent),i;for(i in r)"br"in
e[i]||delete r[i];delete r.pre;var j={tags:{}},n={tags:{}};for(i in r)j.tags[i]=f,n.tags[i]=g;d.addRules(j);l.addRules(n)})();l.addRules({text:function(a){return a.replace(/\xa0/g,"&nbsp;")}});var c=/<(a|area|img|input)\b([^>]*)>/gi,j=/\b(href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi,h="{ke_protected}",f=/(?:<textarea[^>]*>[\s\S]*<\/textarea>)|(?:<style[^>]*>[\s\S]*<\/style>)|(?:<script[^>]*>[\s\S]*<\/script>)|(?:<(:?link|meta|base)[^>]*>)/gi,g=/<ke:encoded>([^<]*)<\/ke:encoded>/gi,
y=/(<\/?)((?:object|embed|param|html|body|head|title|noscript)[^>]*>)/gi,z=/(<\/?)ke:((?:object|embed|param|html|body|head|title|noscript)[^>]*>)/gi,q=/<ke:(param|embed)([^>]*?)\/?>(?!\s*<\/ke:\1)/gi;a.htmlDataProcessor={dataFilter:d,htmlFilter:l,toHtml:function(a){m.webkit&&(a=a.replace(/\u200b/g,""));var b=new t.BeautifyWriter;(new t.Parser(a)).parse().writeHtml(b,l);return a=b.getHtml()},toDataFormat:function(a,b){var b=b||d,a=w(a),a=i(a),a=a.replace(y,"$1ke:$2"),a=a.replace(q,"<ke:$1$2></ke:$1>"),
c=new p("<div>");c.html("a"+a);a=c.html().substr(1);a=a.replace(z,"$1$2");a=n(a);c=new t.BasicWriter;(new t.Parser(a)).parse().writeHtml(c,b);return a=c.getHtml()},toServer:function(a){var b=new t.MinifyWriter;(new t.Parser(a)).parse().writeHtml(b,l);return b.getHtml()}}}}});
KISSY.add("editor/selectionFix",["./base","./selection","node"],function(a,b){function o(a){function b(a,c){var d=g.body.createTextRange();try{d.moveToPoint(a,c)}catch(f){d=s}return d}function d(){var a=g.selection.createRange();i&&!a.item&&0===a.compareEndPoints("StartToEnd",a)&&i.select();f.detach("mouseup",d);f.detach("mousemove",c);i=e=0}function c(a){if(a.button){if(a=b(a.pageX,a.pageY))0<a.compareEndPoints("StartToStart",i)?a.setEndPoint("StartToStart",i):a.setEndPoint("EndToEnd",i),a.select()}else d()}
var e,h=a.get("window")[0],f=a.get("document"),g=f[0],i;f.on("mousedown contextmenu",function(a){var n=g.documentElement;if(a.target===n&&(e&&d(),!(n.scrollHeight>n.clientHeight)&&(e=1,i=b(a.pageX,a.pageY))))f.on("mouseup",d),f.on("mousemove",c),h.focus(),i.select()})}function t(b){function l(a){if(f){var c=b.getSelection(),e=c&&c.getType(),g=c&&d.selection;if(a&&g&&e===w.SELECTION_NONE&&!d.queryCommandEnabled("InsertImage"))setTimeout(function(){l(i)},50);else{var j;if(!g||!g.type||!("Control"!==
g.type&&(j=g.createRange())&&(j=j.parentElement())&&(j=j.nodeName)&&j.toLowerCase()in{input:1,textarea:1}))h=g&&c.getRanges()[0],b.checkSelectionChange()}}}var d=b.get("document")[0],c=new e(d.body),j=new e(d.documentElement);if(8>a.UA.ieMode)j.on("click",function(a){"html"===(new e(a.target)).nodeName()&&b.getSelection().getNative().createRange().select()});var h,f,g=i;j.on("mousedown",function(){g=v});j.on("mouseup",function(){g=i});c.on("focusin",function(a){if("body"===(new e(a.target)).nodeName()&&
h){try{g&&h.select()}catch(b){}h=s}});c.on("focus",function(){f=i;l()});c.on("beforedeactivate",function(a){a.relatedTarget||(f=v,g=i)});c.on("mousedown",function(){f=v});c.on("mouseup",function(){f=i;setTimeout(function(){l(i)},0)});c.on("keydown",function(){f=v});c.on("keyup",function(){f=i;setTimeout(function(){l()},0)})}function m(a){a.get("document").on("mouseup keyup selectionchange",function(){a.checkSelectionChange()})}function x(a){function b(a){var c=p.XHTML_DTD;return a._4eIsBlockBoundary()&&
c.$empty[a.nodeName()]}function d(a){return j(a)&&h(a)}var c=/\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|\u00A0|&#160;|(<\!--[\s\S]*?--\>))?\s*(:?<\/\1>)?(?=\s*$|<\/body>)/gi,j=p.Walker.whitespaces(i),h=p.Walker.bookmark(v,i),f=function(a){return j(a)&&8!==a.nodeType};a.on("selectionChange",function(g){var h=g.path,j=a.get("document")[0],m=new e(j.body),g=(g=g.selection)&&g.getRanges()[0],o=h.blockLimit;m[0]||(j.documentElement.appendChild(j.createElement("body")),m=new e(j.body),
g&&(g.setStart(m,0),g.collapse(1)));o=o||m;if(k.gecko){var s=(j=h.block||h.blockLimit)&&j.last(d);j&&j._4eIsBlockBoundary()&&(!s||!(1===s[0].nodeType&&s._4eIsBlockBoundary()))&&"pre"!==j.nodeName()&&!j._4eGetBogus()&&j._4eAppendBogus()}if(g&&g.collapsed&&!h.block){if("body"===o.nodeName()){"html"===g.startContainer.nodeName()&&g.setStart(m,0);if((h=g.fixBlock(i,"p"))&&h[0]!==m[0].lastChild&&h.outerHtml().match(c))if((j=h.next(f,1))&&j[0].nodeType===u.NodeType.ELEMENT_NODE&&!b[j])g.moveToElementEditablePosition(j),
h._4eRemove();else if((j=h.prev(f,1))&&j[0].nodeType===u.NodeType.ELEMENT_NODE&&!b[j])g.moveToElementEditablePosition(j,j.outerHtml().match(c)?v:i),h._4eRemove();g.select();a.notifySelectionChange()}h=a.get("document")[0];g=new p.Range(h);g.moveToElementEditablePosition(m,i);"body"!==(new p.ElementPath(g.startContainer)).blockLimit.nodeName()&&(m=(new e(h.createElement("p"))).appendTo(m),k.ie||m._4eAppendBogus())}})}var p=b("./base");b("./selection");var e=b("node"),i=!0,v=!1,s=null,k=a.UA,u=a.DOM,
w=p.SelectionType;return{init:function(a){a.docReady(function(){if(document.selection)o(a),t(a);else if(m(a),k.ie){var b,d=a.get("document");d.on("focusout",function(){b=a.getSelection().getRanges()});d.on("focusin",function(){b&&(a.getSelection().selectRanges(b),b=null)})}});x(a)}}});
KISSY.add("editor/plugin-meta",[],function(){(function(a){a({"editor/plugin/back-color":{requires:["editor/plugin/color/btn","editor/plugin/back-color/cmd"]}});a({"editor/plugin/back-color/cmd":{requires:["editor/plugin/color/cmd"]}});a({"editor/plugin/bold":{requires:["editor/plugin/font/ui","editor/plugin/bold/cmd","editor/plugin/button"]}});a({"editor/plugin/bold/cmd":{requires:["editor","editor/plugin/font/cmd"]}});a({"editor/plugin/bubble":{requires:["overlay","editor"]}});a({"editor/plugin/button":{requires:["editor",
"button"]}});a({"editor/plugin/checkbox-source-area":{requires:["editor"]}});a({"editor/plugin/code":{requires:["editor","editor/plugin/button","editor/plugin/dialog-loader"]}});a({"editor/plugin/code/dialog":{requires:["editor","menubutton","editor/plugin/dialog"]}});a({"editor/plugin/color/btn":{requires:["editor","editor/plugin/button","editor/plugin/overlay","editor/plugin/dialog-loader"]}});a({"editor/plugin/color/cmd":{requires:["editor"]}});a({"editor/plugin/color/dialog":{requires:["editor",
"editor/plugin/dialog"]}});a({"editor/plugin/contextmenu":{requires:["editor","menu","editor/plugin/focus-fix","event"]}});a({"editor/plugin/dent-cmd":{requires:["editor","editor/plugin/list-utils"]}});a({"editor/plugin/dialog-loader":{requires:["editor","overlay"]}});a({"editor/plugin/dialog":{requires:["editor","overlay","editor/plugin/focus-fix","dd/plugin/constrain","component/plugin/drag"]}});a({"editor/plugin/draft":{requires:"editor,json,event,editor/plugin/local-storage,overlay,editor/plugin/menubutton".split(",")}});
a({"editor/plugin/drag-upload":{requires:["editor","event"]}});a({"editor/plugin/element-path":{requires:["editor"]}});a({"editor/plugin/fake-objects":{requires:["editor","html-parser"]}});a({"editor/plugin/flash-bridge":{requires:["editor","swf","event"]}});a({"editor/plugin/flash-common/base-class":{requires:"editor/plugin/flash-common/utils,base,editor,editor/plugin/dialog-loader,editor/plugin/bubble,editor/plugin/contextmenu".split(",")}});a({"editor/plugin/flash-common/utils":{requires:["swf"]}});
a({"editor/plugin/flash":{requires:["editor","editor/plugin/flash-common/base-class","editor/plugin/flash-common/utils","editor/plugin/fake-objects","editor/plugin/button"]}});a({"editor/plugin/flash/dialog":{requires:["editor","editor/plugin/flash-common/utils","editor/plugin/dialog","editor/plugin/menubutton"]}});a({"editor/plugin/focus-fix":{requires:["editor"]}});a({"editor/plugin/font-family":{requires:["editor","editor/plugin/font/ui","editor/plugin/font-family/cmd","editor/plugin/menubutton"]}});
a({"editor/plugin/font-family/cmd":{requires:["editor/plugin/font/cmd"]}});a({"editor/plugin/font-size":{requires:["editor","editor/plugin/font/ui","editor/plugin/font-size/cmd","editor/plugin/menubutton"]}});a({"editor/plugin/font-size/cmd":{requires:["editor/plugin/font/cmd"]}});a({"editor/plugin/font/cmd":{requires:["editor"]}});a({"editor/plugin/font/ui":{requires:["editor","editor/plugin/button","editor/plugin/menubutton"]}});a({"editor/plugin/fore-color":{requires:["editor/plugin/color/btn",
"editor/plugin/fore-color/cmd"]}});a({"editor/plugin/fore-color/cmd":{requires:["editor/plugin/color/cmd"]}});a({"editor/plugin/heading":{requires:["editor/plugin/menubutton","editor","editor/plugin/heading/cmd"]}});a({"editor/plugin/heading/cmd":{requires:["editor"]}});a({"editor/plugin/image":{requires:["editor/plugin/button","editor","editor/plugin/bubble","editor/plugin/dialog-loader","editor/plugin/contextmenu"]}});a({"editor/plugin/image/dialog":{requires:["editor","io","editor/plugin/dialog",
"tabs","editor/plugin/menubutton"]}});a({"editor/plugin/indent":{requires:["editor","editor/plugin/indent/cmd","editor/plugin/button"]}});a({"editor/plugin/indent/cmd":{requires:["editor/plugin/dent-cmd"]}});a({"editor/plugin/italic":{requires:["editor/plugin/font/ui","editor/plugin/italic/cmd","editor/plugin/button"]}});a({"editor/plugin/italic/cmd":{requires:["editor","editor/plugin/font/cmd"]}});a({"editor/plugin/justify-center":{requires:["editor","editor/plugin/justify-center/cmd","editor/plugin/button"]}});
a({"editor/plugin/justify-center/cmd":{requires:["editor/plugin/justify-cmd"]}});a({"editor/plugin/justify-cmd":{requires:["editor"]}});a({"editor/plugin/justify-left":{requires:["editor","editor/plugin/justify-left/cmd","editor/plugin/button"]}});a({"editor/plugin/justify-left/cmd":{requires:["editor/plugin/justify-cmd"]}});a({"editor/plugin/justify-right":{requires:["editor","editor/plugin/justify-right/cmd","editor/plugin/button"]}});a({"editor/plugin/justify-right/cmd":{requires:["editor/plugin/justify-cmd"]}});
a({"editor/plugin/link":{requires:["editor/plugin/button","editor/plugin/bubble","editor","editor/plugin/link/utils","editor/plugin/dialog-loader"]}});a({"editor/plugin/link/dialog":{requires:["editor","editor/plugin/dialog","editor/plugin/link/utils"]}});a({"editor/plugin/link/utils":{requires:["editor"]}});a({"editor/plugin/list-utils":{requires:["editor"]}});a({"editor/plugin/list-utils/btn":{requires:["editor","editor/plugin/button","editor/plugin/menubutton"]}});a({"editor/plugin/list-utils/cmd":{requires:["editor",
"editor/plugin/list-utils"]}});a({"editor/plugin/local-storage":{requires:["editor","overlay","editor/plugin/flash-bridge"]}});a({"editor/plugin/maximize":{requires:["editor/plugin/maximize/cmd","editor/plugin/button"]}});a({"editor/plugin/maximize/cmd":{requires:["editor","event"]}});a({"editor/plugin/menubutton":{requires:["editor","menubutton"]}});a({"editor/plugin/ordered-list":{requires:["editor/plugin/list-utils/btn","editor/plugin/ordered-list/cmd"]}});a({"editor/plugin/ordered-list/cmd":{requires:["editor",
"editor/plugin/list-utils/cmd"]}});a({"editor/plugin/outdent":{requires:["editor","editor/plugin/button","editor/plugin/outdent/cmd"]}});a({"editor/plugin/outdent/cmd":{requires:["editor","editor/plugin/dent-cmd"]}});a({"editor/plugin/overlay":{requires:["editor","overlay","editor/plugin/focus-fix"]}});a({"editor/plugin/page-break":{requires:["editor","editor/plugin/fake-objects","editor/plugin/button"]}});a({"editor/plugin/preview":{requires:["editor/plugin/button"]}});a({"editor/plugin/progressbar":{requires:["base"]}});
a({"editor/plugin/remove-format":{requires:["editor","editor/plugin/button","editor/plugin/remove-format/cmd"]}});a({"editor/plugin/remove-format/cmd":{requires:["editor"]}});a({"editor/plugin/resize":{requires:["dd"]}});a({"editor/plugin/separator":{requires:["editor"]}});a({"editor/plugin/smiley":{requires:["editor","editor/plugin/overlay","editor/plugin/button"]}});a({"editor/plugin/source-area":{requires:["editor","editor/plugin/button"]}});a({"editor/plugin/strike-through":{requires:["editor/plugin/font/ui",
"editor/plugin/strike-through/cmd","editor/plugin/button"]}});a({"editor/plugin/strike-through/cmd":{requires:["editor","editor/plugin/font/cmd"]}});a({"editor/plugin/table":{requires:["editor","editor/plugin/dialog-loader","editor/plugin/contextmenu","editor/plugin/button"]}});a({"editor/plugin/table/dialog":{requires:["editor","editor/plugin/dialog","editor/plugin/menubutton"]}});a({"editor/plugin/underline":{requires:["editor/plugin/font/ui","editor/plugin/underline/cmd","editor/plugin/button"]}});
a({"editor/plugin/underline/cmd":{requires:["editor","editor/plugin/font/cmd"]}});a({"editor/plugin/undo":{requires:["editor","editor/plugin/undo/btn","editor/plugin/undo/cmd","editor/plugin/button"]}});a({"editor/plugin/undo/btn":{requires:["editor/plugin/button","editor"]}});a({"editor/plugin/undo/cmd":{requires:["editor"]}});a({"editor/plugin/unordered-list":{requires:["editor/plugin/list-utils/btn","editor/plugin/unordered-list/cmd"]}});a({"editor/plugin/unordered-list/cmd":{requires:["editor",
"editor/plugin/list-utils/cmd"]}});a({"editor/plugin/video":{requires:["editor","editor/plugin/flash-common/utils","editor/plugin/flash-common/base-class","editor/plugin/fake-objects","editor/plugin/button"]}});a({"editor/plugin/video/dialog":{requires:["editor","io","editor/plugin/flash/dialog","editor/plugin/menubutton"]}});a({"editor/plugin/word-filter":{requires:["html-parser"]}});a({"editor/plugin/xiami-music":{requires:["editor","editor/plugin/flash-common/base-class","editor/plugin/flash-common/utils",
"editor/plugin/fake-objects","editor/plugin/button"]}});a({"editor/plugin/xiami-music/dialog":{requires:["editor","editor/plugin/flash/dialog","editor/plugin/menubutton"]}})})(function(a){KISSY.config("modules",a)},KISSY.Features,KISSY.UA)});
KISSY.add("editor/styles",["node","./selection","./range","./base","./elementPath"],function(a,b){function o(a){return!F.attr(a,"_ke_bookmark")}function t(a,b){for(var c in a)"string"===typeof a[c]?a[c]=a[c].replace(R,function(a,c){return b[c]}):t(a[c],b)}function m(b,c){c&&(b=a.clone(b),t(b,c));var d=this.element=this.element=(b.element||"*").toLowerCase();this.type=this.type="#text"===d||N[d]?A.STYLE_BLOCK:O[d]?A.STYLE_OBJECT:A.STYLE_INLINE;this._={definition:b}}function x(a,b){var c=b?this.removeFromRange:
this.applyToRange;a.body.focus();for(var d=new y(a),f=d.getRanges(),e=0;e<f.length;e++)c.call(this,f[e]);d.selectRanges(f)}function p(a,b,c){var d=a.element;"*"===d&&(d="span");b=new g(b.createElement(d));c&&c._4eCopyAttributes(b);c=a._.definition;a=c.attributes;c=m.getStyleText(c);if(a)for(var f in a)b.attr(f,a[f]);c&&(b[0].style.cssText=c);return b}function e(a){var b=a.createBookmark(B),c=a.createIterator();c.enforceRealBlocks=B;c.enlargeBr=B;for(var d,f=a.document;d=c.getNextParagraph();){var e=
p(this,f,d),h=e,e="pre"===h.nodeName,r="pre"===d.nodeName,j=!e&&r;e&&!r?(r=d,j=r.html(),j=i(j,/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g,""),j=j.replace(/[ \t\r\n]*(<br[^>]*>)[ \t\r\n]*/gi,"$1"),j=j.replace(/([ \t\n\r]+|&nbsp;)/g," "),j=j.replace(/<br\b[^>]*>/gi,"\n"),M.ie?(r=r[0].ownerDocument.createElement("div"),r.appendChild(h[0]),h.outerHtml("<pre>"+j+"</pre>"),h=new g(r.firstChild),h._4eRemove()):h.html(j)):j?h=s(v(d),h):d._4eMoveChildren(h);d[0].parentNode.replaceChild(h[0],d[0]);if(e&&(d=h,e=void 0,
(e=d._4ePreviousSourceNode(B,F.NodeType.ELEMENT_NODE))&&"pre"===e.nodeName()))h=i(e.html(),/\n$/,"")+"\n\n"+i(d.html(),/^\n/,""),M.ie?d.outerHtml("<pre>"+h+"</pre>"):d.html(h),e._4eRemove()}a.moveToBookmark(b)}function i(a,b,c){var d="",f="",a=a.replace(/(^<span[^>]+_ke_bookmark.*?\/span>)|(<span[^>]+_ke_bookmark.*?\/span>$)/gi,function(a,b,c){b&&(d=b);c&&(f=c);return""});return d+a.replace(b,c)+f}function v(a){var b=[];i(a.outerHtml(),/(\S\s*)\n(?:\s|(<span[^>]+_ck_bookmark.*?\/span>))*\n(?!$)/gi,
function(a,b,c){return b+"</pre>"+c+"<pre>"}).replace(/<pre\b.*?>([\s\S]*?)<\/pre>/gi,function(a,c){b.push(c)});return b}function s(a,b){for(var c=b[0].ownerDocument.createDocumentFragment(),d=0;d<a.length;d++){var f=a[d],f=f.replace(/(\r\n|\r)/g,"\n"),f=i(f,/^[ \t]*\n/,""),f=i(f,/\n$/,""),f=i(f,/^[ \t]+|[ \t]+$/g,function(a,b){return 1===a.length?"&nbsp;":b?" "+Array(a.length).join("&nbsp;"):Array(a.length).join("&nbsp;")+" "}),f=f.replace(/\n/g,"<br>"),f=f.replace(/[ \t]{2,}/g,function(a){return Array(a.length).join("&nbsp;")+
" "}),e=b.clone();e.html(f);c.appendChild(e[0])}return c}function k(a){var b=a.document;if(a.collapsed)b=p(this,b,void 0),a.insertNode(b),a.moveToPosition(b,r.POSITION_BEFORE_END);else{var c=this.element,d=this._.definition,f,e=L[c];e||(f=B,e=L.span);var h=a.createBookmark();a.enlarge(r.ENLARGE_ELEMENT);a.trim();for(var i=a.createBookmark(),l=i.startNode,i=i.endNode,A=l,m;A&&A[0];){var k=I;if(F.equals(A,i))A=G,k=B;else{var n=A[0].nodeType,s=n===F.NodeType.ELEMENT_NODE?A.nodeName():G;if(s&&A.attr("_ke_bookmark")){A=
A._4eNextSourceNode(B);continue}if(!s||e[s]&&(A._4ePosition(i)|E.POSITION_PRECEDING|E.POSITION_IDENTICAL|E.POSITION_IS_CONTAINED)===E.POSITION_PRECEDING+E.POSITION_IDENTICAL+E.POSITION_IS_CONTAINED&&(!d.childRule||d.childRule(A))){var q=A.parent();if(q&&"a"===c&&q.nodeName()===c)n=p(this,b,void 0),q._4eMoveChildren(n),q[0].parentNode.replaceChild(n[0],q[0]),n._4eMergeSiblings();else if(q&&q[0]&&((L[q.nodeName()]||L.span)[c]||f)&&(!d.parentRule||d.parentRule(q))){if(!m&&(!s||!L.$removeEmpty[s]||(A._4ePosition(i)|
E.POSITION_PRECEDING|E.POSITION_IDENTICAL|E.POSITION_IS_CONTAINED)===E.POSITION_PRECEDING+E.POSITION_IDENTICAL+E.POSITION_IS_CONTAINED))m=new z(b),m.setStartBefore(A);if(n===F.NodeType.TEXT_NODE||n===F.NodeType.ELEMENT_NODE&&!A[0].childNodes.length){q=A;for(n=null;(k=!q.next(o,1))&&(n=q.parent())&&e[n.nodeName()]&&(n._4ePosition(l)|E.POSITION_FOLLOWING|E.POSITION_IDENTICAL|E.POSITION_IS_CONTAINED)===E.POSITION_FOLLOWING+E.POSITION_IDENTICAL+E.POSITION_IS_CONTAINED&&(!d.childRule||d.childRule(n));)q=
n;m.setEndAfter(q)}}else k=B}else k=B;A=A._4eNextSourceNode()}if(k&&m&&!m.collapsed){for(var k=p(this,b,void 0),q=m.getCommonAncestor(),n={},s={},u,t=null,v;k&&q&&k[0]&&q[0];){if(q.nodeName()===c){for(u in d.attributes)if(!s[u]&&(v=q.attr(t)))k.attr(u)===v?k.removeAttr(u):s[u]=1;for(t in d.styles)if(!n[t]&&(v=q.style(t)))k.style(t)===v?k.style(t,""):n[t]=1;if(!k._4eHasAttributes()){k=G;break}}q=q.parent()}k?(k[0].appendChild(m.extractContents()),j(this,k),m.insertNode(k),k._4eMergeSiblings(),M.ie||
k[0].normalize()):(k=new g(b.createElement("span")),k[0].appendChild(m.extractContents()),m.insertNode(k),j(this,k),k._4eRemove(!0));m=G}}l._4eRemove();i._4eRemove();a.moveToBookmark(h);a.shrink(r.SHRINK_TEXT)}}function u(a){a.enlarge(r.ENLARGE_ELEMENT);var b=a.createBookmark(),c=b.startNode;if(a.collapsed){for(var f=new D(c.parent()),e,i=0,j;i<f.elements.length&&(j=f.elements[i])&&!(j===f.block||j===f.blockLimit);i++)if(this.checkElementRemovable(j)){var A=a.checkBoundaryOfElement(j,r.END),E=!A&&
a.checkBoundaryOfElement(j,r.START);E||A?(e=j,e.match=E?"start":"end"):(j._4eMergeSiblings(),j.nodeName()!==this.element?(A=l(this),h(j,A[j.nodeName()]||A["*"])):d(this,j))}if(e){j=c;for(i=0;;i++){A=f.elements[i];if(A.equals(e))break;else if(A.match)continue;else A=A.clone();A[0].appendChild(j[0]);j=A}j["start"===e.match?"insertBefore":"insertAfter"](e);f=e.html();!f||"\u200b"===f?e.remove():M.webkit&&J(a.document.createTextNode("\u200b")).insertBefore(j)}}else{var k=b.endNode,m=this;e=function(){for(var a=
new D(c.parent()),b=new D(k.parent()),d=G,f,e=G,g=0;g<a.elements.length;g++){f=a.elements[g];if(f===a.block||f===a.blockLimit)break;m.checkElementRemovable(f)&&(d=f)}for(g=0;g<b.elements.length;g++){f=b.elements[g];if(f===b.block||f===b.blockLimit)break;m.checkElementRemovable(f)&&(e=f)}e&&k._4eBreakParent(e);d&&c._4eBreakParent(d)};e();for(f=new g(c[0].nextSibling);f[0]!==k[0];){i=f._4eNextSourceNode();if(f[0]&&f[0].nodeType===F.NodeType.ELEMENT_NODE&&this.checkElementRemovable(f)&&(f.nodeName()===
this.element?d(this,f):(j=l(this),h(f,j[f.nodeName()]||j["*"])),i[0].nodeType===F.NodeType.ELEMENT_NODE&&i.contains(c)))e(),i=new g(c[0].nextSibling);f=i}}a.moveToBookmark(b)}function w(a){var b={};(""+a).replace(/&quot;/g,'"').replace(/\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g,function(a,c,d){b[c]=d});return b}function n(a,b){var c="";b!==I?(c=document.createElement("span"),c.style.cssText=a,c=c.style.cssText||""):c=a;return c.replace(/\s*([;:])\s*/,"$1").replace(/([^\s;])$/,"$1;").replace(/,\s+/g,
",").toLowerCase()}function l(b){if(b._.overrides)return b._.overrides;var c=b._.overrides={},d=b._.definition.overrides;if(d){a.isArray(d)||(d=[d]);for(var f=0;f<d.length;f++){var e=d[f],g,h,r;"string"===typeof e?g=e.toLowerCase():(g=e.element?e.element.toLowerCase():b.element,h=e.attributes,r=e.styles);e=c[g]||(c[g]={});if(h){g=e.attributes=e.attributes||[];for(var i in h)g.push([i.toLowerCase(),h[i]])}if(r){var e=e.styles=e.styles||[],j;for(j in r)e.push([j.toLowerCase(),r[j]])}}}return c}function d(b,
d){var e=b._.definition,g=l(b),h=a.merge(e.attributes,(g[d.nodeName()]||g["*"]||{}).attributes),e=a.merge(e.styles,(g[d.nodeName()]||g["*"]||{}).styles),g=a.isEmptyObject(h)&&a.isEmptyObject(e),r;for(r in h)("class"===r||b._.definition.fullMatch)&&d.attr(r)!==c(r,h[r])||(g=g||!!d.hasAttr(r),d.removeAttr(r));for(var i in e)b._.definition.fullMatch&&d.style(i)!==c(i,e[i],B)||(g=g||!!d.style(i),d.style(i,""));f(d)}function c(a,b,c){var d=new g("<span>");d[c?"style":"attr"](a,b);return d[c?"style":"attr"](a)}
function j(a,b){for(var c=l(a),f=b.all(a.element),e=f.length;0<=--e;)d(a,new g(f[e]));for(var r in c)if(r!==a.element){f=b.all(r);for(e=f.length-1;0<=e;e--){var i=new g(f[e]);h(i,c[r])}}}function h(a,b){var c,d,e=b&&b.attributes;if(e)for(c=0;c<e.length;c++){var g=e[c][0];if(d=a.attr(g)){var h=e[c][1];(h===G||h.test&&h.test(d)||"string"===typeof h&&d===h)&&a[0].removeAttribute(g)}}if(e=b&&b.styles)for(c=0;c<e.length;c++)if(g=e[c][0],h=a.css(g)){var r=e[c][1];(r===G||r.test&&r.test(d)||"string"===typeof r&&
h===r)&&a.css(g,"")}f(a)}function f(a){if(!a._4eHasAttributes()){var b=a[0].firstChild,c=a[0].lastChild;a._4eRemove(B);b&&(b.nodeType===F.NodeType.ELEMENT_NODE&&F._4eMergeSiblings(b),c&&b!==c&&c.nodeType===F.NodeType.ELEMENT_NODE&&F._4eMergeSiblings(c))}}var g=b("node"),y=b("./selection"),z=b("./range"),q=b("./base"),D=b("./elementPath"),B=!0,I=!1,G=null,J=a.all,F=a.DOM,r=q.RangeType,E=q.PositionType,A,M=a.UA,N={address:1,div:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,p:1,pre:1},L=q.XHTML_DTD,O={embed:1,hr:1,
img:1,li:1,object:1,ol:1,table:1,td:1,tr:1,th:1,ul:1,dl:1,dt:1,dd:1,form:1},P=/\s*(?:;\s*|$)/g,R=/#\((.+?)\)/g;q.StyleType=A={STYLE_BLOCK:1,STYLE_INLINE:2,STYLE_OBJECT:3};m.prototype={constructor:m,apply:function(a){x.call(this,a,I)},remove:function(a){x.call(this,a,B)},applyToRange:function(a){return(this.applyToRange=this.type===A.STYLE_INLINE?k:this.type===A.STYLE_BLOCK?e:G).call(this,a)},removeFromRange:function(a){return(this.removeFromRange=this.type===A.STYLE_INLINE?u:G).call(this,a)},checkElementRemovable:function(a,
b){if(!a)return I;var c,d=this._.definition,f;if(a.nodeName()===this.element){if(!b&&!a._4eHasAttributes())return B;var e=d._AC;if(!e){var e={},g=0,h=d.attributes;if(h)for(var r in h)g++,e[r]=h[r];if(h=m.getStyleText(d))e.style||g++,e.style=h;e._length=g;d._AC=e}d=e;if(d._length){for(c in d)if("_length"!==c){g=a.attr(c)||"";if("style"===c)a:{e=d[c];g=n(g,I);"string"===typeof e&&(e=w(e));"string"===typeof g&&(g=w(g));h=void 0;for(h in e)if(!(h in g&&(g[h]===e[h]||"inherit"===e[h]||"inherit"===g[h]))){e=
I;break a}e=B}else e=d[c]===g;if(e){if(!b)return B}else if(b)return I}if(b)return B}else return B}c=l(this);if(c=c[a.nodeName()]||c["*"]){if(!(d=c.attributes)&&!(f=c.styles))return B;if(d)for(e=0;e<d.length;e++)if(c=d[e][0],c=a.attr(c))if(g=d[e][1],g===G||"string"===typeof g&&c===g||g.test&&g.test(c))return B;if(f)for(e=0;e<f.length;e++)if(c=a.css(f[e][0]))if(d=f[e][1],d===G||"string"===typeof d&&c===d||d.test&&d.test(c))return B}return I},checkActive:function(a){switch(this.type){case A.STYLE_BLOCK:return this.checkElementRemovable(a.block||
a.blockLimit,B);case A.STYLE_OBJECT:case A.STYLE_INLINE:for(var b=a.elements,c=0,d;c<b.length;c++)if(d=b[c],!(this.type===A.STYLE_INLINE&&(F.equals(d,a.block)||F.equals(d,a.blockLimit))))if((this.type!==A.STYLE_OBJECT||d.nodeName()in O)&&this.checkElementRemovable(d,B))return B}return I}};m.getStyleText=function(a){var b=a._ST;if(b)return b;var b=a.styles,c=a.attributes&&a.attributes.style||"",d="";c.length&&(c=c.replace(P,";"));for(var e in b){var f=b[e],g=(e+":"+f).replace(P,";");"inherit"===f?
d+=g:c+=g}c.length&&(c=n(c));c+=d;return a._ST=c};return q.Style=m});
KISSY.add("editor/domIterator",["node","./walker","./range","./base","./elementPath"],function(a,b){function o(a){1>arguments.length||(this.range=a,this.forceBrBreak=v,this.enlargeBr=i,this.enforceRealBlocks=v,this._=this._||{})}var t=b("node"),m=b("./walker"),x=b("./range"),p=b("./base"),e=b("./elementPath"),i=!0,v=!1,s=a.UA,k=p.RangeType,u=a.DOM,w=/^[\r\n\t ]*$/;a.augment(o,{getNextParagraph:function(b){var l,d,c,j,h,f;if(!this._.lastNode){c=this.range.clone();c.shrink(k.SHRINK_ELEMENT,i);c.enlarge(this.forceBrBreak||
!this.enlargeBr?k.ENLARGE_LIST_ITEM_CONTENTS:k.ENLARGE_BLOCK_CONTENTS);d=new m(c);var g=m.bookmark(i,i);d.evaluator=g;this._.nextNode=d.next();d=new m(c);d.evaluator=g;d=d.previous();this._.lastNode=d._4eNextSourceNode(i);this._.lastNode&&this._.lastNode[0].nodeType===u.NodeType.TEXT_NODE&&!a.trim(this._.lastNode[0].nodeValue)&&this._.lastNode.parent()._4eIsBlockBoundary()&&(g=new x(c.document),g.moveToPosition(this._.lastNode,k.POSITION_AFTER_END),g.checkEndOfBlock()&&(g=new e(g.endContainer),this._.lastNode=
(g.block||g.blockLimit)._4eNextSourceNode(i)));this._.lastNode||(this._.lastNode=this._.docEndMarker=new t(c.document.createTextNode("")),u.insertAfter(this._.lastNode[0],d[0]));c=null}g=this._.nextNode;d=this._.lastNode;for(this._.nextNode=null;g;){var o=v,p=g[0].nodeType!==u.NodeType.ELEMENT_NODE,q=v;if(p)g[0].nodeType===u.NodeType.TEXT_NODE&&w.test(g[0].nodeValue)&&(p=v);else{var D=g.nodeName();if(g._4eIsBlockBoundary(this.forceBrBreak&&{br:1})){if("br"===D)p=i;else if(!c&&!g[0].childNodes.length&&
"hr"!==D){l=g;j=g.equals(d);break}c&&(c.setEndAt(g,k.POSITION_BEFORE_START),"br"!==D&&(this._.nextNode=g));o=i}else{if(g[0].firstChild){c||(c=new x(this.range.document),c.setStartAt(g,k.POSITION_BEFORE_START));g=new t(g[0].firstChild);continue}p=i}}p&&!c&&(c=new x(this.range.document),c.setStartAt(g,k.POSITION_BEFORE_START));j=(!o||p)&&g.equals(d);if(c&&!o)for(;!g[0].nextSibling&&!j;){D=g.parent();if(D._4eIsBlockBoundary(this.forceBrBreak&&{br:1})){o=i;j||D.equals(d);break}g=D;p=i;j=g.equals(d);q=
i}p&&c.setEndAt(g,k.POSITION_AFTER_END);g=g._4eNextSourceNode(q,null,d);if((j=!g)||o&&c)break}if(!l){if(!c)return this._.docEndMarker&&this._.docEndMarker._4eRemove(),this._.nextNode=null;l=new e(c.startContainer);g=l.blockLimit;o={div:1,th:1,td:1};l=l.block;if((!l||!l[0])&&!this.enforceRealBlocks&&o[g.nodeName()]&&c.checkStartOfBlock()&&c.checkEndOfBlock())l=g;else if(!l||this.enforceRealBlocks&&"li"===l.nodeName())l=new t(this.range.document.createElement(b||"p")),l[0].appendChild(c.extractContents()),
l._4eTrim(),c.insertNode(l),h=f=i;else if("li"!==l.nodeName()){if(!c.checkStartOfBlock()||!c.checkEndOfBlock())l=l.clone(v),l[0].appendChild(c.extractContents()),l._4eTrim(),f=c.splitBlock(),h=!f.wasStartOfBlock,f=!f.wasEndOfBlock,c.insertNode(l)}else j||(this._.nextNode=l.equals(d)?null:c.getBoundaryNodes().endNode._4eNextSourceNode(i,null,d))}h&&(c=new t(l[0].previousSibling),c[0]&&c[0].nodeType===u.NodeType.ELEMENT_NODE&&("br"===c.nodeName()?c._4eRemove():c[0].lastChild&&"br"===u.nodeName(c[0].lastChild)&&
u._4eRemove(c[0].lastChild)));f&&(c=m.bookmark(v,i),h=new t(l[0].lastChild),h[0]&&h[0].nodeType===u.NodeType.ELEMENT_NODE&&"br"===h.nodeName()&&(s.ie||h.prev(c,1)||h.next(c,1))&&h.remove());this._.nextNode||(this._.nextNode=j||l.equals(d)?null:l._4eNextSourceNode(i,null,d));return l}});x.prototype.createIterator=function(){return new o(this)};return o});
KISSY.add("editor/z-index-manager",["./base"],function(a,b){var o=b("./base"),t=o.ZIndexManager={BUBBLE_VIEW:1100,POPUP_MENU:1200,STORE_FLASH_SHOW:99999,MAXIMIZE:900,OVERLAY:9999,LOADING:11E3,LOADING_CANCEL:12E3,SELECT:1200};o.baseZIndex=function(a){return(o.Config.baseZIndex||1E4)+a};return t});
KISSY.add("editor","node,editor/iframe-content-tpl,editor/base,editor/utils,editor/focusManager,editor/clipboard,editor/enterKey,editor/htmlDataProcessor,editor/selectionFix,editor/plugin-meta,editor/styles,editor/domIterator,editor/z-index-manager".split(","),function(a,b,o,t){function m(a,b){var c=a.body;I(function(){a.designMode="on";setTimeout(function N(){a.designMode="off";c.focus();if(!N.retry)N.retry=h},50)},function(){a.designMode="off";c.setAttribute("contentEditable",false);c.setAttribute("contentEditable",
true);b||m(a,1)})}function x(b){var c=b.get("textarea")[0],d=b.get("window"),e=b.get("document"),g=e[0];if(z.webkit){e.on("click",function(b){var c=new s(b.target);a.inArray(c.nodeName(),["input","select"])&&b.preventDefault()});e.on("mouseup",function(b){var c=new s(b.target);a.inArray(c.nodeName(),["input","textarea"])&&b.preventDefault()})}if(z.gecko||z.ie||z.opera){var h;h=(new s('<span tabindex="-1" style="position:absolute; left:-10000" role="presentation"></span>')).insertAfter(c);h.on("focus",
function(){b.focus()});b.activateGecko=function(){z.gecko&&b.__iframeFocus&&h[0].focus()};b.on("destroy",function(){h.detach();h.remove()})}d.on("focus",function(){z.gecko?m(g,f):z.opera&&g.body.focus();b.notifySelectionChange()});if(z.gecko)e.on("mousedown",function(){b.__iframeFocus||m(g,f)});if(q){e.on("keydown",function(a){if(a.keyCode in{8:1,46:1}){var c=b.getSelection(),d=c.getSelectedElement();if(d){b.execCommand("save");var e=c.getRanges()[0].createBookmark();d.remove();c.selectBookmarks([e]);
b.execCommand("save");a.preventDefault()}}});if(g.compatMode==="CSS1Compat"){var i={33:1,34:1};e.on("keydown",function(a){a.keyCode in i&&setTimeout(function(){b.getSelection().scrollIntoView()},0)})}}if(z.webkit)e.on("mousedown",function(c){c=new s(c.target);a.inArray(c.nodeName(),["img","hr","input","textarea","select"])&&b.getSelection().selectElement(c)});if(z.gecko)e.on("dragstart",function(a){var b=new s(a.target);b.nodeName()==="img"&&/ke_/.test(b[0].className)&&a.preventDefault()});n.add(b)}
function p(b,c,d,e){var f="",h;h=w.debugUrl("theme/editor-iframe.css");d=d.concat([]);d.unshift(h);for(h=0;h<d.length;h++)f=f+a.substitute('<link href="{href}" rel="stylesheet" />',{href:d[h]});return a.substitute(k,{doctype:a.UA.ieMode===8?'<meta http-equiv="X-UA-Compatible" content="IE=7" />':"",title:"{title}",links:f,style:"<style>"+c+"</style>",data:e||"",script:b?'<script id="ke_active_script">'+(B(g).isCustomDomain()?'document.domain="'+y.domain+'";':"")+"parent.KISSY.require('editor')._initIframe(\""+
b+'");<\/script>':""})}function e(a,b){function c(){h=g.document;a.setInternal("document",new s(h));a.setInternal("window",new s(g));d.detach();h.open("text/html","replace");h.write(e);h.close()}var d=a.get("iframe"),e=p(a.get("id"),a.get("customStyle"),a.get("customLink"),b),f=d[0],g=f.contentWindow,h;d.__loaded=1;try{h=g.document}catch(i){f.src=f.src;if(q<7){setTimeout(c,10);return}}c()}function i(b,c){var d=B(g).getEmptyIframeSrc()||"";d&&(d=' src="'+d+'" ');var d=new s(a.substitute(G,{iframeSrc:d,
prefixCls:b.get("prefixCls")})),f=b.get("textarea");f.hasAttr("tabindex")&&d.attr("tabindex",z.webkit?-1:f.attr("tabindex"));f.parent().prepend(d);b.set("iframe",d);b.__docReady=0;if(z.gecko&&!d.__loaded)d.on("load",function(){e(b,c)},b);else e(b,c)}function v(b){if(b.get("iframe")){var c=b.get("iframe"),d=b.get("window"),b=b.get("document"),e=b[0],f=B(e.documentElement),e=B(e.body);a.each([b,f,e,d],function(a){a.detach()});c.remove()}}var s=b("node"),k=b("editor/iframe-content-tpl"),u=b("editor/base"),
w=b("editor/utils"),n=b("editor/focusManager"),l=b("editor/clipboard"),d=b("editor/enterKey"),c=b("editor/htmlDataProcessor"),j=b("editor/selectionFix");b("editor/plugin-meta");b("editor/styles");b("editor/domIterator");b("editor/z-index-manager");t.exports=u;var h=true,f=false,g=a.Env.host,y=g.document,z=a.UA,q=z.ieMode<11,D=s.NodeType,B=s.all,I=w.tryThese,G='<iframe class="{prefixCls}editor-iframe" frameborder="0"  title="kissy-editor"  allowTransparency="true"  {iframeSrc} ></iframe>',J=/^(?:<(p)>)?(?:(?:&nbsp;)|\s|<br[^>]*>)*(?:<\/\1>)?$/i;
u.Mode={SOURCE_MODE:0,WYSIWYG_MODE:1};u.addMembers({initializer:function(){this.__commands={};this.__controls={};n.register(this)},renderUI:function(){l.init(this);d.init(this);c.init(this);j.init(this)},bindUI:function(){function a(){b.detach("docReady",a);if(b.get("focused"))b.focus();else{var c=b.getSelection();c&&c.removeAllRanges()}}var b=this,c,d=b.get("prefixCls"),e=b.get("textarea");if(b.get("attachForm")&&(c=e[0].form)&&(c=B(c)))c.on("submit",b.sync,b);b.on("docReady",a);b.on("blur",function(){b.$el.removeClass(d+
"editor-focused")});b.on("focus",function(){b.$el.addClass(d+"editor-focused")})},_onSetHeight:function(a){var b=this.get("textarea"),c=this.get("toolBarEl"),d=this.get("statusBarEl"),a=parseInt(a,10),a=a-((c&&c.outerHeight()||0)+(d&&d.outerHeight()||0));b.parent().css("height",a);b.css("height",a)},_onSetMode:function(a){var b=this.get("iframe"),c=this.get("textarea");if(a===1){this.setData(c.val());c.hide();this.fire("wysiwygMode")}else{if(b){c.val(this.getFormatData(1));b.hide()}c.show();this.fire("sourceMode")}},
_onSetFocused:function(a){a&&this.__docReady&&this.focus()},destructor:function(){var b,c=this.get("textarea"),d=this.get("document");this.get("attachForm")&&(b=c[0].form)&&(b=B(b))&&b.detach("submit",this.sync,this);if(d){b=B(d[0].body);var c=B(d[0].documentElement),e=this.get("window");n.remove(this);d.detach();c.detach();b.detach();e.detach()}a.each(this.__controls,function(a){a.destroy&&a.destroy()});this.__commands={};this.__controls={}},sync:function(){this.get("textarea").val(this.getData())},
getControl:function(a){return this.__controls[a]},getControls:function(){return this.__controls},addControl:function(a,b){this.__controls[a]=b},showDialog:function(a,b){var a=a+"/dialog",c=this.__controls[a];c.show(b);this.fire("dialogShow",{dialog:c.dialog,pluginDialog:c,dialogName:a})},addCommand:function(a,b){this.__commands[a]=b},hasCommand:function(a){return this.__commands[a]},execCommand:function(b){var c=this.__commands[b],d=a.makeArray(arguments);d.shift();d.unshift(this);if(c)return c.exec.apply(c,
d)},queryCommandValue:function(a){return this.execCommand(w.getQueryCmd(a))},setData:function(a){var b,c=a;if(this.get("mode")!==1)this.get("textarea").val(a);else{if(b=this.htmlDataProcessor)c=b.toDataFormat(a);v(this);i(this,c)}},getData:function(b,c){var d=this.htmlDataProcessor,e;c===void 0&&(c=this.get("mode"));e=c===1&&this.isDocReady()?this.get("document")[0].body.innerHTML:d.toDataFormat(this.get("textarea").val());e=b?d.toHtml(e):d.toServer(e);e=a.trim(e);J.test(e)&&(e="");return e},getFormatData:function(a){return this.getData(1,
a)},getDocHtml:function(){return p(0,this.get("customStyle"),this.get("customLink"),this.getFormatData())},getSelection:function(){return u.Selection.getSelection(this.get("document")[0])},getSelectedHtml:function(){var a=this.getSelection().getRanges()[0],b="";if(a){a=a.cloneContents();b=this.get("document")[0].createElement("div");b.appendChild(a);b=b.innerHTML}return b},focus:function(){var a=this.get("window");if(a){var b=this.get("document")[0],a=a[0];z.ie||a&&a.parent&&a.parent.focus();a&&a.focus();
try{b.body.focus()}catch(c){}this.notifySelectionChange()}},blur:function(){this.get("window")[0].blur();this.get("document")[0].body.blur()},addCustomStyle:function(a,b){var c=this.get("window"),d=this.get("customStyle")||"";this.set("customStyle",d+("\n"+a));c&&c.addStyleSheet(a,b)},removeCustomStyle:function(a){this.get("document").on("#"+a).remove()},addCustomLink:function(a){var b=this.get("customLink"),c=this.get("document")[0];b.push(a);this.set("customLink",b);b=c.createElement("link");b.rel=
"stylesheet";c.getElementsByTagName("head")[0].appendChild(b);b.href=a},removeCustomLink:function(b){this.get("document").all("link").each(function(a){a.attr("href")===b&&a.remove()});var c=this.get("customLink"),d=a.indexOf(b,c);d!==-1&&c.splice(d,1)},docReady:function(a){this.on("docReady",a);this.__docReady&&a.call(this)},isDocReady:function(){return this.__docReady},checkSelectionChange:function(){var a=this;a.__checkSelectionChangeId&&clearTimeout(a.__checkSelectionChangeId);a.__checkSelectionChangeId=
setTimeout(function(){var b=a.getSelection();if(b&&!b.isInvalid){var c=b.getStartElement(),d=new u.ElementPath(c);if(!a.__previousPath||!a.__previousPath.compare(d)){a.__previousPath=d;a.fire("selectionChange",{selection:b,path:d,element:c})}}},100)},notifySelectionChange:function(){this.__previousPath=null;this.checkSelectionChange()},insertElement:function(a){if(this.get("mode")===1){this.focus();var b,c=a.nodeName(),d=u.XHTML_DTD,e=d.$block[c],f=u.RangeType,g=(c=this.getSelection())&&c.getRanges(),
i,j,k;if(g&&g.length!==0){this.execCommand("save");for(j=g.length-1;j>=0;j--){i=g[j];b=!j&&a||a.clone(h);i.insertNodeByDtd(b);k||(k=b)}if(k){i.moveToPosition(k,f.POSITION_AFTER_END);if(e){a=u.Walker.whitespaces(true);(a=(k=k.next(a,1))&&k[0].nodeType===D.ELEMENT_NODE&&k.nodeName())&&d.$block[a]&&d[a]["#text"]&&i.moveToElementEditablePosition(k)}c.selectRanges([i]);this.focus();b&&b[0].nodeType===1&&b.scrollIntoView(void 0,{alignWithTop:false,allowHorizontalScroll:true,onlyScrollIfNeeded:true});F.call(this);
return b}}}},insertHtml:function(a,b){var c=this,d,e=c.get("document")[0];if(c.get("mode")===1){if(d=c.htmlDataProcessor)a=d.toDataFormat(a,b);c.focus();c.execCommand("save");if(d=e.selection){d.type==="Control"&&d.clear();try{d.createRange().pasteHTML(a)}catch(f){}}else{d=c.get("iframe")[0].contentWindow.getSelection();var g=d.getRangeAt(0);g.deleteContents();var h=e.createElement("div");h.innerHTML=a;for(var e=e.createDocumentFragment(),i,j;i=h.firstChild;)j=e.appendChild(i);g.insertNode(e);if(j){g=
g.cloneRange();g.setStartAfter(j);g.collapse(true);d.removeAllRanges();d.addRange(g)}}setTimeout(function(){c.getSelection().scrollIntoView()},50);F.call(c)}}});u.decorate=function(a,b){var b=b||{},a=B(a),c=b.textareaAttrs=b.textareaAttrs||{},d=a.style("width"),e=a.style("height"),f=a.attr("name");if(d)b.width=b.width||d;if(e)b.height=b.height||e;if(f)c.name=f;b.data=b.data||a.val();b.elBefore=a;c=(new u(b)).render();a.remove();return c};u._initIframe=function(a){var b=n.getInstance(a),a=b.get("document"),
c=a[0];a.one("#ke_active_script").remove();x(b);var d=c.body,e=B(d);if(q){d.hideFocus=h;d.disabled=h;d.contentEditable=h;d.removeAttribute("disabled")}else setTimeout(function(){z.gecko||z.opera?d.contentEditable=h:z.webkit?d.parentNode.contentEditable=h:c.designMode="on"},0);if(z.gecko||z.opera){var g=c.documentElement;B(g).on("mousedown",function(a){if(a.target===g){z.gecko&&m(c,f);b.activateGecko()}})}setTimeout(function(){q&&setTimeout(function(){if(c){d.runtimeStyle.marginBottom="0px";d.runtimeStyle.marginBottom=
""}},1E3)},0);setTimeout(function(){b.__docReady=1;b.fire("docReady");var a=b.get("disableObjectResizing"),d=b.get("disableInlineTableEditing");if(a||d)try{c.execCommand("enableObjectResizing",f,!a);c.execCommand("enableInlineTableEditing",f,!d)}catch(g){e.on(q?"resizestart":"resize",function(b){var c=new s(b.target);(a||c.nodeName()==="table"&&d)&&b.preventDefault()})}},10)};var F=a.buffer(function(){this.execCommand("save")},50)});
